]> git.karo-electronics.de Git - karo-tx-linux.git/commit
lib/parser.c: avoid overflow in match_number()
authorAlex Elder <elder@inktank.com>
Thu, 13 Sep 2012 01:01:11 +0000 (11:01 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 18 Sep 2012 06:04:38 +0000 (16:04 +1000)
commit409bc3ef805bebf6b88cf5b7c363b01bd069d93a
tree6e454b7503e6ccb31487e4e809e162149ebba6f3
parent53bde06e13e882b5b6ea2138eaae3879d57fff3a
lib/parser.c: avoid overflow in match_number()

The result of converting an integer value to another signed integer type
that's unable to represent the original value is implementation defined.
(See notes in section 6.3.1.3 of the C standard.)

In match_number(), the result of simple_strtol() (which returns type long)
is assigned to a value of type int.

Instead, handle the result of simple_strtol() in a well-defined way, and
return -ERANGE if the result won't fit in the int variable used to hold
the parsed result.

No current callers pay attention to the particular error value returned,
so this additional return code shouldn't do any harm.

Signed-off-by: Alex Elder <elder@inktank.com>
Cc: Randy Dunlap <rdunlap@xenotime.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/parser.c