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

From: Linus Torvalds
Date: Fri Mar 09 2018 - 14:05:23 EST


On Fri, Mar 9, 2018 at 7:01 AM, Petr Mladek <pmladek@xxxxxxxx> 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