Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752886AbbGAICy (ORCPT ); Wed, 1 Jul 2015 04:02:54 -0400 Received: from mga14.intel.com ([192.55.52.115]:31276 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752030AbbGAICk (ORCPT ); Wed, 1 Jul 2015 04:02:40 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,384,1432623600"; d="scan'208";a="517058366" Message-ID: <55939E08.5080004@intel.com> Date: Wed, 01 Jul 2015 16:00:08 +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] lib/bitmap.c: fix a special string handling bug in __bitmap_parselist References: <55935B19.5080103@intel.com> <55936976.7090001@intel.com> In-Reply-To: <55936976.7090001@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1131 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/