]> git.karo-electronics.de Git - karo-tx-linux.git/commit
lib/parser.c: avoid overflow in match_number()
authorAlex Elder <elder@inktank.com>
Fri, 7 Sep 2012 00:24:51 +0000 (10:24 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 7 Sep 2012 05:36:28 +0000 (15:36 +1000)
commit0f12706e1c7aa3e3bbb3ef3b87453943e18b0d1d
treeeacf09278ff0c5124dd68cc529764fcb1b50180d
parent29d35cfe2ff22ae8c34caa7cea1d0a70a7189ca9
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