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>
This commit is contained in:
Родитель
d21c3d4d1c
Коммит
d9282cb663
|
@ -546,6 +546,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
b = 0;
|
b = 0;
|
||||||
in_range = 1;
|
in_range = 1;
|
||||||
|
at_start = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,6 +559,9 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
|
||||||
at_start = 0;
|
at_start = 0;
|
||||||
totaldigits++;
|
totaldigits++;
|
||||||
}
|
}
|
||||||
|
/* if no digit is after '-', it's wrong*/
|
||||||
|
if (at_start && in_range)
|
||||||
|
return -EINVAL;
|
||||||
if (!(a <= b))
|
if (!(a <= b))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (b >= nmaskbits)
|
if (b >= nmaskbits)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче