Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753569AbbBPSt0 (ORCPT ); Mon, 16 Feb 2015 13:49:26 -0500 Received: from mail-we0-f180.google.com ([74.125.82.180]:50068 "EHLO mail-we0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753028AbbBPStY (ORCPT ); Mon, 16 Feb 2015 13:49:24 -0500 From: Anshul Garg X-Google-Original-From: Anshul Garg To: linux-kernel@vger.kernel.org Cc: aksgarg1989@gmail.com, anshul.g@samsung.com, torvalds@linux-foundation.org Subject: [PATCH] lib/kstrtox.c Stop parsing integer on overflow Date: Mon, 16 Feb 2015 10:48:50 -0800 Message-Id: <1424112530-116810-1-git-send-email-aksgarg1989@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: X-Antivirus: avast! (VPS 150216-0, 02/16/2015), Outbound message X-Antivirus-Status: Clean Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1094 Lines: 39 From: Anshul Garg While converting string representation to integer break the loop if overflow is detected. Signed-off-by: Anshul Garg --- lib/kstrtox.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/kstrtox.c b/lib/kstrtox.c index ec8da78..6f30209 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -70,8 +70,10 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long * it in the max base we support (16) */ if (unlikely(res & (~0ull << 60))) { - if (res > div_u64(ULLONG_MAX - val, base)) + if (res > div_u64(ULLONG_MAX - val, base)) { overflow = 1; + break; + } } res = res * base + val; rv++; -- 1.7.9.5 --- This email has been checked for viruses by Avast antivirus software. http://www.avast.com -- 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/