From patchwork Sat Jun 3 07:47:25 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: 9764015 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 42770603D7 for ; Sat, 3 Jun 2017 07:47:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 333552858A for ; Sat, 3 Jun 2017 07:47:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2257A2859A; Sat, 3 Jun 2017 07:47:37 +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 BCE582858A for ; Sat, 3 Jun 2017 07:47:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751202AbdFCHrg (ORCPT ); Sat, 3 Jun 2017 03:47:36 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35472 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751200AbdFCHrf (ORCPT ); Sat, 3 Jun 2017 03:47:35 -0400 Received: by mail-wm0-f66.google.com with SMTP id g15so22043882wmc.2 for ; Sat, 03 Jun 2017 00:47:34 -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=rJS6JyXo8cHhMZmejFPtEq81aLzZLOd51Yh8CLFGdy7XaIns16OfCfu0JbK9Q+ouvQ 2SDg5hDn4wOh9KA3t1T39yYaJiM2fzX52C6kT7maOFhYA2fHilVLg0Jt3GAcf01pWjVD AH1H4/1/UxrG4+xGxYp0vnHVbDHVC0CQYUW+rbX+Yjs7SNyMVDerBqaf+/aSVAjlp1jn fcGQgRFyw3O4VbCyI8Si4f9EyEqQuwxH0JYqY03UKz9wGX1qgd9cAMw5vDjJi5yIMTQu 160bM79cPInuVqitaHO3U9pFEkhDINYtHEqdJVsVKnsFgR54vs7u3H/LoPZSWkAEZsld bmSg== 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=enyQecp5/UzQvkOsLB3SXGXYgyAL47AV4P3nPb40CV4yMYkTFgHiVIw2aOn94Rh4en SZLwPI3HXwkOG5xNmxls/6abQyQ8S2E3uolkE6qJugc+ItqSSW/C7OEOQnY8OxjvsYkg Hpld3GtoTCYYIo1Jo3/XEaUbJTgqsANLmk/va84gLHzGZAqAgnImk2Go/8LGDsGEEy25 rZ3OoZH7TaMG2MxD7WOV2fZixkOacppmsdy4CVRyhmOTjglvcijdoK2V9ir9pYOFLrYd HEHrH1WkvSlxEUOe5EaQSKvB7Xd2F1UWselht4GDnaj+I9cFAr9iss6DCIRZKukQwxFr kPYw== X-Gm-Message-State: AODbwcCAt3+sgNXmnrOq0Cew6LnmZ4NMhQxyRdC3kZtdjGWl9YeqQZ6j qcl9Jcic82x165ii1OY= X-Received: by 10.80.179.209 with SMTP id t17mr8981459edd.62.1496476054008; Sat, 03 Jun 2017 00:47:34 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:89c:5400:65b4:e9ec:d7a6:723a]) by smtp.gmail.com with ESMTPSA id f48sm126331eda.42.2017.06.03.00.47.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Jun 2017 00:47:33 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Chris Li , Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v2 1/3] memcpy()'s byte count is unsigned Date: Sat, 3 Jun 2017 09:47:25 +0200 Message-Id: <20170603074727.66945-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170603074727.66945-1-luc.vanoostenryck@gmail.com> References: <20170603074727.66945-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; }