aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPan Xinhui <xinhuix.pan@intel.com>2015-07-20 08:57:13 +1000
committerStephen Rothwell <sfr@canb.auug.org.au>2015-07-22 14:31:50 +1000
commit5425fefb0ae79cff690d1cac340ed39d3d721a6f (patch)
tree2564ea8bf8ca805df541c2f83ab7e6e49df4449d
parent7c4c747e31f2d0f782bac69b8f53b65d70ec58d2 (diff)
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 <xinhuix.pan@intel.com> Cc: Yury Norov <yury.norov@gmail.com> Cc: Chris Metcalf <cmetcalf@ezchip.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r--lib/bitmap.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index eb21456be4b9..f549176e9250 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -546,6 +546,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
return -EINVAL;
b = 0;
in_range = 1;
+ at_start = 1;
continue;
}
@@ -558,6 +559,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)