Re: [PATCH v3] vsprintf: Prevent crash when dereferencing invalid pointers

Steven Rostedt
2018-03-16T14:32:12Z

On Fri, 16 Mar 2018 09:55:56 +0100
Petr Mladek <pmladek@suse.com> wrote:

> I am not sure if it is worth it. I think that we would catch 99% of
> problems by checking the first byte.

Then it should be commented as such. Something like:

/*
* This is not a fool-proof test. 99.9% of the time that this will
* fault is due to a bad pointer, not one that crosses into bad memory.
* Just test the address to make sure it doesn't fault due to a poorly
* added printk during debugging.
*/

>
> This patch was motivated by a code clean up rather than bug reports.
> The original patch removed two more strict checks and kept only
> the check for pure NULL. I suggested that it was the wrong way to
> go...
>
> I do not want to go suddenly to the other extreme. I suggest to start
> with simple check for the first byte and see how often it helps
> in the real life. We could always extend it later.

Fair enough. If this is just code clean up, then sure, we don't need to
cover all cases. But it should definitely be commented about why this
is added, and if in the future we really do want this to be more
robust, then we can extend it.

-- Steve