From patchwork Thu Jun 1 20:27:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9761085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 99F47602BC for ; Thu, 1 Jun 2017 20:27:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C1B02832D for ; Thu, 1 Jun 2017 20:27:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80D3A2852D; Thu, 1 Jun 2017 20:27:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D0332832D for ; Thu, 1 Jun 2017 20:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751161AbdFAU1i (ORCPT ); Thu, 1 Jun 2017 16:27:38 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36272 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751125AbdFAU1g (ORCPT ); Thu, 1 Jun 2017 16:27:36 -0400 Received: by mail-wm0-f68.google.com with SMTP id k15so14123959wmh.3 for ; Thu, 01 Jun 2017 13:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uRO4M00UsgLjY//go+ae6lKGUOqqwrBUfUJL0vhu/og=; b=vYkTUgS+mPBtK51azRv6wBzazlf4JoPnzAl+B5apfmz8ruIsdeP/FpI9Hpq/KJmJTk 0D1+RqrYvXLVcZ18cFsYCNvB6yYRo+I+jHl39mN+9s345+8xm+9gMRsmbajmDNWLsx6G ocMUDeEPP3/4b1BLU2UD21i/bfK3bbD/BJwiyK2ZuHz98Q/Go0lqSyAZNKQaYQYYPNg9 SPRCZD+0sgwd5gjrMQVzo223DIqLWKZsk9wH2AsP8sr9BwsezEON+IPWVuVy9EcQezD7 R9JeeRjs1MsqE9/G27BmmUP7/m5/PKR4jqHe+OcAj6FPHqD2EHYuXaO9y5bo9Bu4afrq DtTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uRO4M00UsgLjY//go+ae6lKGUOqqwrBUfUJL0vhu/og=; b=T2rtRopIji0/l0iqb3S5Nn3GM+7/5pC5d1wYE3rDT3e5NwyMKahATrqw2JTCSsltkh Yu9qaDAZdUHAYoldgFlgHRwB7OUAR6JTcWTKXqTvTXcXUliVTEE2IWm9rX97t6O3Oef0 bbW/zrOjfWNGsJYQC4s5nQ46u1vlJjel6cKkBiC5kWvSyjL0xi3xSuJEJatAtcz7c1MN 15/zKwRjc+aAQ4WzG6hcomu1xoygzpnzduBGC4j4ixHIZtu96+OVgMC7FQcCBWtvpNsu xkBblaP5DRx/zoQQhuWm2Rv0i9LuUQmo5so88pX0Z3KyfgApRZSG/FTiNkV02yVbB+zo 5Zcg== X-Gm-Message-State: AODbwcAoafGMyypLqWBZ6uHzddab9mh3x9iy0IjMX1BmMUH/PC5+kU1b IWDtOQ7cH680y74Ar64= X-Received: by 10.223.130.77 with SMTP id 71mr2522597wrb.21.1496348855397; Thu, 01 Jun 2017 13:27:35 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:89c:5400:c519:ec79:50ce:6fe3]) by smtp.gmail.com with ESMTPSA id t27sm1427510wra.35.2017.06.01.13.27.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 13:27:34 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Chris Li , Ramsay Jones , Junio C Hamano , Luc Van Oostenryck Subject: [PATCH 1/3] memcpy()'s byte count is unsigned Date: Thu, 1 Jun 2017 22:27:22 +0200 Message-Id: <20170601202724.77597-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170601202724.77597-1-luc.vanoostenryck@gmail.com> References: <84e547c2-8a5b-225c-1363-361e091821f4@ramsayjones.plus.com> <20170601202724.77597-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The checker part of sparse does some checking on memcpy(), memset(), copy_{from,to}_user() byte count and warn if the value is known to be too large. The comparison is done with signed numbers and it also warns if the value is negative. However these functions take an unsigned byte count (size_t) and so the value can't really be negative. Additionaly, the number of bits used by sparse internally may not be the same as the one used for the target's size_t. So sparse's check against negative value may not be the same as checking if the target's value would be so-large-than-the-upper-bit-is-set. Change this by removing the test for negative values and simply do an unsigned compare. Signed-off-by: Luc Van Oostenryck --- sparse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sparse.c b/sparse.c index 02ab97743..1cb90e20d 100644 --- a/sparse.c +++ b/sparse.c @@ -152,9 +152,9 @@ static void check_byte_count(struct instruction *insn, pseudo_t count) if (!count) return; if (count->type == PSEUDO_VAL) { - long long val = count->value; - if (val <= 0 || val > 100000) - warning(insn->pos, "%s with byte count of %lld", + unsigned long long val = count->value; + if (val > 100000ULL) + warning(insn->pos, "%s with byte count of %llu", show_ident(insn->func->sym->ident), val); return; }