On Wed, Nov 10, 2010 at 13:38 -0800, David Rientjes wrote:
I don't think so, this fix is more theoretical than practical.
However, maybe there is some crazy driver that fills array of 2GB with
s*printf().
What do you mean here?
$ make lib/vsprintf.o
CHK include/linux/version.h
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
CC lib/vsprintf.o
Compiled without warnings.
[...]
This comparison is intended for size_t _underflow_, e.g. in such (buggy)
code:
len = snprintf(buf, sizeof(buf), "%s", string);
len += snprintf(buf + len, sizeof(buf) - len, "%s", string2);
If the first snprintf() returns len that is greater than sizeof(buf),
then sizeof(buf)-len is negative; casted to (unsigned!) size_t it
becomes some big value. buf+len points to somewhere after the real buf.
To detect this situation we check whether size is negative (as signed).
But it should be checked as integer of the same size.
OK, this should be changed to LONG_MAX.
From vsnprintf comment:
* The return value is the number of characters which would
* be generated for the given input, excluding the trailing
If nothing was filled then result is zero.
--
Vasiliy
--