From: Pan Xinhui <xinhuix.pan@intel.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Yury Norov <yury.norov@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
tj@kernel.org, peterz@infradead.org, sudeep.holla@arm.com,
mina86@mina86.com, "mnipxh@163.com" <mnipxh@163.com>,
Alexey Klimov <klimov.linux@gmail.com>,
"yanmin_zhang@linux.intel.com" <yanmin_zhang@linux.intel.com>
Subject: [PATCH 2/3, RESEND] lib/bitmap.c: fix a special string handling bug in __bitmap_parselist
Date: Wed, 01 Jul 2015 18:51:38 +0800 [thread overview]
Message-ID: <5593C63A.7000106@intel.com> (raw)
In-Reply-To: <5593C5F2.2090000@intel.com>
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>
---
lib/bitmap.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/bitmap.c b/lib/bitmap.c
index eb21456..f549176 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)
--
1.9.1
next prev parent reply other threads:[~2015-07-01 10:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-01 10:50 [PATCH 1/3, RESEND] lib/bitmap.c: correct a code style and do some, optimization Pan Xinhui
2015-07-01 10:51 ` Pan Xinhui [this message]
2015-07-01 10:52 ` [PATCH 3/3, RESEND] lib/bitmap.c: bitmap_parselist can accept string with whitespaces on head or tail Pan Xinhui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5593C63A.7000106@intel.com \
--to=xinhuix.pan@intel.com \
--cc=akpm@linux-foundation.org \
--cc=klimov.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mina86@mina86.com \
--cc=mnipxh@163.com \
--cc=peterz@infradead.org \
--cc=sudeep.holla@arm.com \
--cc=tj@kernel.org \
--cc=yanmin_zhang@linux.intel.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.