Skip to content

Commit 7b88f76

Browse files
milabsgregkh
authored andcommitted
lib/cmdline.c: fix get_options() overflow while parsing ranges
commit a91e0f680bcd9e10c253ae8b62462a38bd48f09f upstream. 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/2613C75C-B04D-4BFF-82A6-12F97BA0F620@gmail.com Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.com> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b95aa98 commit 7b88f76

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/cmdline.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
* the values[M, M+1, ..., N] into the ints array in get_options.
2323
*/
2424

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

2929
(*str)++;
3030
upper_range = simple_strtol((*str), NULL, 0);
3131
inc_counter = upper_range - *pint;
32-
for (x = *pint; x < upper_range; x++)
32+
for (x = *pint; n && x < upper_range; x++, n--)
3333
*pint++ = x;
3434
return inc_counter;
3535
}
@@ -96,7 +96,7 @@ char *get_options(const char *str, int nints, int *ints)
9696
break;
9797
if (res == 3) {
9898
int range_nums;
99-
range_nums = get_range((char **)&str, ints + i);
99+
range_nums = get_range((char **)&str, ints + i, nints - i);
100100
if (range_nums < 0)
101101
break;
102102
/*

0 commit comments

Comments
 (0)