Skip to content

Commit a91e0f6

Browse files
milabstorvalds
authored andcommitted
lib/cmdline.c: fix get_options() overflow while parsing ranges
When using get_options() it's possible to specify a range of numbers, like 1-100500. The problem is that it doesn't track array size while calling internally to get_range() which iterates over the range and fills the memory with numbers. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ilya V. Matveychikov <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1eb643d commit a91e0f6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/cmdline.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
* the values[M, M+1, ..., N] into the ints array in get_options.
2424
*/
2525

26-
static int get_range(char **str, int *pint)
26+
static int get_range(char **str, int *pint, int n)
2727
{
2828
int x, inc_counter, upper_range;
2929

3030
(*str)++;
3131
upper_range = simple_strtol((*str), NULL, 0);
3232
inc_counter = upper_range - *pint;
33-
for (x = *pint; x < upper_range; x++)
33+
for (x = *pint; n && x < upper_range; x++, n--)
3434
*pint++ = x;
3535
return inc_counter;
3636
}
@@ -97,7 +97,7 @@ char *get_options(const char *str, int nints, int *ints)
9797
break;
9898
if (res == 3) {
9999
int range_nums;
100-
range_nums = get_range((char **)&str, ints + i);
100+
range_nums = get_range((char **)&str, ints + i, nints - i);
101101
if (range_nums < 0)
102102
break;
103103
/*

0 commit comments

Comments
 (0)