summaryrefslogtreecommitdiffstats
path: root/lib/cmdline.c
diff options
context:
space:
mode:
authorIlya Matveychikov <matvejchikov@gmail.com>2017-06-23 18:08:49 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-06-23 19:15:55 -0400
commita91e0f680bcd9e10c253ae8b62462a38bd48f09f (patch)
tree38c36b40b5f3c74182d14c346e04c5ae1c853ba2 /lib/cmdline.c
parent1eb643d02b21412e603b42cdd96010a2ac31c05f (diff)
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>
Diffstat (limited to 'lib/cmdline.c')
-rw-r--r--lib/cmdline.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/cmdline.c b/lib/cmdline.c
index 3c6432df7e63..4c0888c4a68d 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -23,14 +23,14 @@
23 * the values[M, M+1, ..., N] into the ints array in get_options. 23 * the values[M, M+1, ..., N] into the ints array in get_options.
24 */ 24 */
25 25
26static int get_range(char **str, int *pint) 26static int get_range(char **str, int *pint, int n)
27{ 27{
28 int x, inc_counter, upper_range; 28 int x, inc_counter, upper_range;
29 29
30 (*str)++; 30 (*str)++;
31 upper_range = simple_strtol((*str), NULL, 0); 31 upper_range = simple_strtol((*str), NULL, 0);
32 inc_counter = upper_range - *pint; 32 inc_counter = upper_range - *pint;
33 for (x = *pint; x < upper_range; x++) 33 for (x = *pint; n && x < upper_range; x++, n--)
34 *pint++ = x; 34 *pint++ = x;
35 return inc_counter; 35 return inc_counter;
36} 36}
@@ -97,7 +97,7 @@ char *get_options(const char *str, int nints, int *ints)
97 break; 97 break;
98 if (res == 3) { 98 if (res == 3) {
99 int range_nums; 99 int range_nums;
100 range_nums = get_range((char **)&str, ints + i); 100 range_nums = get_range((char **)&str, ints + i, nints - i);
101 if (range_nums < 0) 101 if (range_nums < 0)
102 break; 102 break;
103 /* 103 /*