Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754044AbbGAKyP (ORCPT ); Wed, 1 Jul 2015 06:54:15 -0400 Received: from mga01.intel.com ([192.55.52.88]:36305 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753994AbbGAKyJ (ORCPT ); Wed, 1 Jul 2015 06:54:09 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,384,1432623600"; d="scan'208";a="517126976" Message-ID: <5593C63A.7000106@intel.com> Date: Wed, 01 Jul 2015 18:51:38 +0800 From: Pan Xinhui User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: "linux-kernel@vger.kernel.org" CC: Yury Norov , Andrew Morton , Rasmus Villemoes , tj@kernel.org, peterz@infradead.org, sudeep.holla@arm.com, mina86@mina86.com, "mnipxh@163.com" , Alexey Klimov , "yanmin_zhang@linux.intel.com" Subject: [PATCH 2/3, RESEND] lib/bitmap.c: fix a special string handling bug in __bitmap_parselist References: <5593C5F2.2090000@intel.com> In-Reply-To: <5593C5F2.2090000@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1117 Lines: 40 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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/