Skip to content

Commit

Permalink
lib/bitmap.c: fix a special string handling bug in __bitmap_parselist
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Yury Norov <[email protected]>
Cc: Chris Metcalf <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Cc: Sudeep Holla <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Pan Xinhui authored and torvalds committed Sep 10, 2015
1 parent d21c3d4 commit d9282cb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
Expand Down

0 comments on commit d9282cb

Please sign in to comment.