diff options
author | Ilya Matveychikov <matvejchikov@gmail.com> | 2017-06-23 15:08:49 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-06-23 16:15:55 -0700 |
commit | a91e0f680bcd9e10c253ae8b62462a38bd48f09f (patch) | |
tree | 38c36b40b5f3c74182d14c346e04c5ae1c853ba2 | |
parent | 1eb643d02b21412e603b42cdd96010a2ac31c05f (diff) | |
download | op-kernel-dev-a91e0f680bcd9e10c253ae8b62462a38bd48f09f.zip op-kernel-dev-a91e0f680bcd9e10c253ae8b62462a38bd48f09f.tar.gz |
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/2613C75C-B04D-4BFF-82A6-12F97BA0F620@gmail.com
Signed-off-by: Ilya V. Matveychikov <matvejchikov@gmail.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | lib/cmdline.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/cmdline.c b/lib/cmdline.c index 3c6432df..4c0888c 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -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; (*str)++; 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) break; 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) break; /* |