Skip to content

Commit d9282cb

Browse files
Pan Xinhuitorvalds
authored andcommitted
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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d21c3d4 commit d9282cb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/bitmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
546546
return -EINVAL;
547547
b = 0;
548548
in_range = 1;
549+
at_start = 1;
549550
continue;
550551
}
551552

@@ -558,6 +559,9 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
558559
at_start = 0;
559560
totaldigits++;
560561
}
562+
/* if no digit is after '-', it's wrong*/
563+
if (at_start && in_range)
564+
return -EINVAL;
561565
if (!(a <= b))
562566
return -EINVAL;
563567
if (b >= nmaskbits)

0 commit comments

Comments
 (0)