Re: [PATCH] vsprintf: Make "null" pointer dereference more robust

Linus Torvalds
2018-03-09T19:05:20Z

On Fri, Mar 9, 2018 at 7:01 AM, Petr Mladek <pmladek@suse.com> wrote:
> Also it makes the handling unified. We print:
>
> + (null) when pure NULL pointer is dereferenced
> + (efault) when an invalid address is dereferenced
> + pointer address otherwise

This is still fundamentally completely wrong.

It never prints "pointer address", and if it were to do that, it would be wrong.

It should never ever trigger for an address operation, only for the
"we will get _data_ from the ponter".

The strchr thing is also completely broken, and in a very subtle way.
"strchr(string, 0)" is special, and the Open Group states

"The terminating null byte is considered to be part of the string"

so a NUL character will *always* return success, which is actually
completely wrong for this case, because now it does that whole crazy
<efault> thing for %p that it shouldn't do.

Not that I actually verified that our strchr() follows the actual
rules anyway - I personally consider "strchr(string, 0)" to not really
be "special", but be a bug. Either way, the comment is wrong, but the
code is also wrong.

Linus