From nobody Fri Jul 21 08:57:44 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R6k3D53mlz4dPfs; Fri, 21 Jul 2023 08:57:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R6k3D3DJHz4JSg; Fri, 21 Jul 2023 08:57:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689929864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i3DiT7zmZVUbyoh/bz/LN0EYuFGaUFxWc63xQ4Tqu+Y=; b=Xln9LGJpYK1vhTg+mvCLLyWM2nBRvhyQsjb6DM24qTrZano1ZHj+CtuCwsGZGORHhW0n8D kSlltpDldU1UbBFeM20zDL369Km3FWU8sx7HR6m+EDGcyHEZ/ByC+rshK2r5QJbXTnTkeP bo5vf7MFVzzqDKtFEA8fNq74DTU3Nt+6x6rHf1zk3ry/wyiBL4l1hvVC/8xQqQZczSd4cw 8PwKeTX4Pa4xlD34UKOgPhhZNMxeADemF5Zk/SABnpCPnoECsucCcn2BDpt2l/8E2Vm+W2 7vSJWgCexr3cRB8fUVA2DRJSYUgvdsHOsuX1F8I4Z4fbTxM7W0ucCmxJIe/CUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689929864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i3DiT7zmZVUbyoh/bz/LN0EYuFGaUFxWc63xQ4Tqu+Y=; b=Z3PALfWEkX2kd1psOTcR/bD0L2zps14K0+KzN+EbQKRUmcvHxiKFC8uMk5lhxYGgEw3IzB 05o5ux3KTZar9+wctdgk1KpFEf33LSH4AocR++rGiSb3CQYYsdv5FFBY9Y12+afEIG6u4S RuDMDxKIm+s5QyPrWwTWAYrmEcpSww1QFe9RSiF6nX032hAN8DUGsrtcEhLQdyG6oVEwxz 4m2lX/RB/r7AZScs+CH1kczZraif6eeEnjUgMl74F2tt52+jb/X+uqb0kgr4h2QgNLYQ4o X80fU6cHZs6kIfNZsPNZtjdwW6rV7Vz3qi9Cov21B8xuCS+rKCh6n823kDiL/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689929864; a=rsa-sha256; cv=none; b=xtJGP7TwEAiMYrY7B3UCoMwL6OVGAhj+CW8KloPwpE9qLVqmBmVlKyU2lZBcoGJ8V38Crz XE9LXChOksmSnZrcu++rCFxImXO2AQEPPOMDreP1F/0Jly5QOLYF2XQ7/n+iGCb065L+s8 5o4N/Xglrf5N8JJlBOxEUT6xHrO53WXVzJ8xHCtuPiuHJfbOSZudJpiRetgHefzcY+BWz3 eL6oEb1B6NkymqujNL+n61wCAIXsotA5ZFVVa+7PZAScmdo9TzqH2kZcbfDSA40X06htS6 nYFjBDnMws1MMLlD9oTkvqIXbZ3dad9z0FOwzUtI6BCbpPQBeUOUxArFP7WEMw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4R6k3D201Zz166y; Fri, 21 Jul 2023 08:57:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 36L8vi1p045994; Fri, 21 Jul 2023 08:57:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36L8viuA045993; Fri, 21 Jul 2023 08:57:44 GMT (envelope-from git) Date: Fri, 21 Jul 2023 08:57:44 GMT Message-Id: <202307210857.36L8viuA045993@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Robert Clausecker Subject: git: 99544e13eec1 - stable/12 - lib/libc/string/bcmp.c: fix integer overflow bug List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fuz X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 99544e13eec1586552470bd9d5f3b24038891401 Auto-Submitted: auto-generated The branch stable/12 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=99544e13eec1586552470bd9d5f3b24038891401 commit 99544e13eec1586552470bd9d5f3b24038891401 Author: Robert Clausecker AuthorDate: 2023-07-12 18:23:21 +0000 Commit: Robert Clausecker CommitDate: 2023-07-21 08:57:32 +0000 lib/libc/string/bcmp.c: fix integer overflow bug bcmp() returned the number of remaining bytes when the main loop exits. In case of a match, this is zero, else a positive integer. On systems where SIZE_MAX > INT_MAX, the implicit conversion from size_t to int in the return value may cause the number of remaining bytes to overflow, becoming zero and falsely indicating a successful comparison. Fix the bug by always returning 0 on equality, 1 otherwise. PR: 272474 Approved by: emaste Reviewed by: imp MFC After: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D41011 (cherry picked from commit 4da7282a1882fc03c99591c27d44a2e6dfda364b) --- lib/libc/string/bcmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libc/string/bcmp.c b/lib/libc/string/bcmp.c index 96cd49039eee..c42fe79ddb2f 100644 --- a/lib/libc/string/bcmp.c +++ b/lib/libc/string/bcmp.c @@ -51,7 +51,7 @@ bcmp(const void *b1, const void *b2, size_t length) p2 = (char *)b2; do if (*p1++ != *p2++) - break; + return (1); while (--length); - return (length); + return (0); }