Commit a91e0f68 authored by Ilya Matveychikov's avatar Ilya Matveychikov Committed by Linus Torvalds
Browse files

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.


Signed-off-by: default avatarIlya V. Matveychikov <>
Cc: Jonathan Corbet <>
Cc: <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 1eb643d0
......@@ -23,14 +23,14 @@
* the values[M, M+1, ..., N] into the ints array in get_options.
static int get_range(char **str, int *pint)
static int get_range(char **str, int *pint, int n)
int x, inc_counter, upper_range;
upper_range = simple_strtol((*str), NULL, 0);
inc_counter = upper_range - *pint;
for (x = *pint; x < upper_range; x++)
for (x = *pint; n && x < upper_range; x++, n--)
*pint++ = x;
return inc_counter;
......@@ -97,7 +97,7 @@ char *get_options(const char *str, int nints, int *ints)
if (res == 3) {
int range_nums;
range_nums = get_range((char **)&str, ints + i);
range_nums = get_range((char **)&str, ints + i, nints - i);
if (range_nums < 0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment