From 069855b70e052c6377965638b3eda7ca75dbc735 Mon Sep 17 00:00:00 2001 From: Pan Xinhui Date: Wed, 9 Sep 2015 15:37:05 -0700 Subject: lib/bitmap.c: fix a special string handling bug in __bitmap_parselist If string end with '-', for exapmle, bitmap_parselist("1,0-",&mask, nmaskbits), It is not in a valid pattern, so add a check after loop. Return -EINVAL on such condition. Signed-off-by: Pan Xinhui Cc: Yury Norov Cc: Chris Metcalf Cc: Rasmus Villemoes Cc: Sudeep Holla Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- lib/bitmap.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/bitmap.c') diff --git a/lib/bitmap.c b/lib/bitmap.c index 7b2bc1ed4..f1be16ebc 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -557,6 +557,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, return -EINVAL; b = 0; in_range = 1; + at_start = 1; continue; } @@ -569,6 +570,9 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen, at_start = 0; totaldigits++; } + /* if no digit is after '-', it's wrong*/ + if (at_start && in_range) + return -EINVAL; if (!(a <= b)) return -EINVAL; if (b >= nmaskbits) -- cgit v1.2.3