public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/bitmap.c: return -EINVAL for grouping errors in __bitmap_parselist
@ 2015-06-30  7:42 Pan Xinhui
  2015-06-29 13:39 ` Yury Norov
  0 siblings, 1 reply; 11+ messages in thread
From: Pan Xinhui @ 2015-06-30  7:42 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org
  Cc: akpm, linux, tj, peterz, sudeep.holla, mina86, yury.norov,
	mnipxh@163.com

Sometimes the input from user may cause an unexpected result.

just like __bitmap_parse, we return -EINVAL if there is no avaiable digit in each
parsing procedures.

Signed-off-by: Pan Xinhui <xinhuix.pan@intel.com>
---
  lib/bitmap.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/bitmap.c b/lib/bitmap.c
index 64c0926..995fca2 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -504,7 +504,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
  		int nmaskbits)
  {
  	unsigned a, b;
-	int c, old_c, totaldigits;
+	int c, old_c, totaldigits, ndigits;
  	const char __user __force *ubuf = (const char __user __force *)buf;
  	int exp_digit, in_range;
  
@@ -514,6 +514,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
  		exp_digit = 1;
  		in_range = 0;
  		a = b = 0;
+		ndigits = 0;
  
  		/* Get the next cpu# or a range of cpu#'s */
  		while (buflen) {
@@ -555,8 +556,10 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
  			if (!in_range)
  				a = b;
  			exp_digit = 0;
-			totaldigits++;
+			ndigits++; totaldigits++;
  		}
+		if (ndigits == 0)
+			return -EINVAL;
  		if (!(a <= b))
  			return -EINVAL;
  		if (b >= nmaskbits)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-07-01 11:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-30  7:42 [PATCH] lib/bitmap.c: return -EINVAL for grouping errors in __bitmap_parselist Pan Xinhui
2015-06-29 13:39 ` Yury Norov
2015-07-01  1:37   ` Pan Xinhui
2015-06-30  8:01     ` [PATCH] lib/bitmap.c: rewrite __bitmap_parse && __bitmap_parselist Pan Xinhui
2015-06-30  8:31       ` [PATCH V2] " Pan Xinhui
2015-06-30 10:02         ` [PATCH V3] " Pan Xinhui
2015-07-01  3:17           ` Pan Xinhui
2015-07-01  9:16           ` Yury
2015-07-01 11:08             ` Pan Xinhui
2015-06-30  8:32     ` [PATCH] lib/bitmap.c: return -EINVAL for grouping errors in __bitmap_parselist Yury Norov
2015-06-30  8:37       ` Pan Xinhui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox