From nobody Sun Nov 26 04:07:50 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 4SdFYg0bTlz52kMg; Sun, 26 Nov 2023 04:07:51 +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 4SdFYf6pYQz3Fpj; Sun, 26 Nov 2023 04:07:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700971671; 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=tzaVbYpHgA+f+CDPCjhss3LqRIK7N2Fd2N9L+u2+xUk=; b=rOeWIsbAhU9b56zDYZawIRdqrexMa9OtLrbUtmPPJaP7BtVVHCy75gJ0MASaq9qfbv+7TB RePe8QdwaC0pI2iKvfqHkO1g3nzppzPphHzBICQez46uiHOaSvO1QoTVYrWqJSSo+UiPGM Zbwz7QiOFt3XdRBaz6fKwqdIRhMAxa0g50/S9jPlM2x1HAJcQ2Zwqu8w5ghem6bG1hFnvg 3wfCgjroag/wsxofesrWAly+57mvPACa6KzuTX/57VLRmEqXjSoIPo9bPiShi9rWzDlUAG 191rYqUvXjmjmqZmG66b/gV4s3pESZqCMAVOWmfKpYV4lH43dY8ApIWPgDWc0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700971671; 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=tzaVbYpHgA+f+CDPCjhss3LqRIK7N2Fd2N9L+u2+xUk=; b=Y9ajt1bXQGUBZOCYDyn888BHTfsJhkRwDsJ9wkSJrzd2SVXEBk7RkaBw50cCKqfwfKf0wj 6sjv3+Z5UdiYdO++ojCo5G+UBAQYdrE3qsEMx18y6VLBKVWGPDipLsTKgH/OMPfJrpjdGu EseJX4uzeb7jBQ3AIy6aUaLDMcUNZZmNnlu+CDbbowt16OOiY9Ox1nxJsbY6+ZA2zmiUsq ZGd5gJLPwsgpXOzVeDjezYE/H0gg7jlyNqqRe6O5xmwuvgbgd70e5YXq+FfaLyOYV7qXz6 tdALXMjh6bVhbhM3+ZaR0CevDqZQ5bRoQww9QYVJgQSmGa7BsXECc0F31WYzww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700971671; a=rsa-sha256; cv=none; b=uzcdfQBvklo5VuV6TZAWGqMQKoYqCJnZPZNo1EhJJ/ri2mVqO8bBEND99fJ7xFTEMRFL2u pKDZSKYzNZLQkf6iPcGG+4sO6kjbhF7c9qMkPf5yErkncFYvDbRWG55NWK24t3yIhWeMOZ tTqDHORWRny2NuMCf6d26lFrh06myvX4rZ+ZmJdniyjRn6ePbdqaTHUPtFRX9JSkao1irB juFbGhPtxPm0U/H0f7kKJBkEEtFcYl7+rb8456hPABHMph3TIvkNCLcoitO/yeTpJPVOHi U+9legk2ZX3fIHz/yn1yaoMcNHkrjNcAbMc3eI9Lv6RKNuruWkb29i4RDkL8vg== 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 4SdFYf5p91zh43; Sun, 26 Nov 2023 04:07:50 +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 3AQ47oTr028483; Sun, 26 Nov 2023 04:07:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AQ47oSl028480; Sun, 26 Nov 2023 04:07:50 GMT (envelope-from git) Date: Sun, 26 Nov 2023 04:07:50 GMT Message-Id: <202311260407.3AQ47oSl028480@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 4ca702fdccf2 - stable/14 - grep: don't rely on implementation-defined malloc(0) behavior 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 4ca702fdccf239c0a6de7da4a6261284dc08fee0 Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=4ca702fdccf239c0a6de7da4a6261284dc08fee0 commit 4ca702fdccf239c0a6de7da4a6261284dc08fee0 Author: Kyle Evans AuthorDate: 2023-11-05 02:08:36 +0000 Commit: Kyle Evans CommitDate: 2023-11-26 04:07:12 +0000 grep: don't rely on implementation-defined malloc(0) behavior The very few places that rely on malloc/calloc of a zero-size region won't attempt to dereference it, so just return NULL rather than rolling the dice with the underlying malloc implementation. Reported by: brooks, Shawn Webb (cherry picked from commit e116e040f3091eca914a06dcd0bdd9f1aea23add) --- usr.bin/grep/util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 1805cc74bfc6..936abc41b3ef 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -650,6 +650,8 @@ grep_malloc(size_t size) { void *ptr; + if (size == 0) + return (NULL); if ((ptr = malloc(size)) == NULL) err(2, "malloc"); return (ptr); @@ -663,6 +665,8 @@ grep_calloc(size_t nmemb, size_t size) { void *ptr; + if (nmemb == 0 || size == 0) + return (NULL); if ((ptr = calloc(nmemb, size)) == NULL) err(2, "calloc"); return (ptr);