From nobody Sun Nov 05 02:19: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 4SNJ8l0wg9z4yMC4; Sun, 5 Nov 2023 02:19: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 4SNJ8l0SqDz4F90; Sun, 5 Nov 2023 02:19:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699150791; 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=+2R1hz8Xcx25Z+wj6faPkNw//hwC1+k3enk+s4ndfB0=; b=n1jCFwARiYqVOPW9QE0oqSWwAl35UcrWelNBeTp+bQqzwh7rJGM/QcGEYvu7jfD+k2+Zau +aXGtpAUH8bg5GoF/Z/Hmz971oQewDgjLtV3xVQDmn/s1LfRfdebOyKfXro+sFJb2XPc5u zX/WLLhZO1qjDnmT72o7ARLwtaIWYj99++qoMrJR68fzFqq0UcoWkKjGzLzLcN1x8dk4fJ uxTpylAz22DWjsUhAC5W25LIsz6hmz/7XlCHY0uyanYvyR/Am5VxFRrS6G/JYkAN4OizXm qgcmYw2s4KMWaV6geNqNua8CpFPVh3lLa7FN1lpLuveCsip7XolYVaaZmdtlvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699150791; 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=+2R1hz8Xcx25Z+wj6faPkNw//hwC1+k3enk+s4ndfB0=; b=bPWmS4ccbcZHXAHH0xkurwD5K2kvk2ONdRxBG8UtOTTMYwJbF19jh/3Y0H/RUx2d8g2Ja2 OxosVNJdrjRJoyJ8aD992Sm6yfdG4lcEJPavscAgmpd00+RdXCeIrQsTCf6T9BGrQWJOQM 4CenKU0rPGI1U+Kw5B+1vN2akqXIKkmuLqqkUB4MBgdbgwuF8JT9Dh6mWw+MdGE/AQxFef jho4L4zBxuBFJK/vTPBkufr50DLRumC4CZe+CBY1mtC0+pgRBYcl4n9FRZc/wKXT17etpk 4EUU3+RDY8SQFHOqzjHHgg01eZMUigRuRirOJm1WU9kKKnKZKMQpfLFTBmvbBg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699150791; a=rsa-sha256; cv=none; b=qE6oR7XKth1KhFc4VmXp81MV8Y9MHMcxmWUDGgP8YUZqlpKdqMGP5XbUFJ4cOGjz3rZf51 nXcOhKRLWJnFNTas7RdJa6mpuFXjLntVXXrMGalFNI7JcleRr4R4AXbmEApl2WLNz5jIDP e7tOIMiOj7c3qNlCK7aK3mc4zGkLHaH/NOLKEWyYDQ17b1kdTr7O8ziy74uPaeeuAE2lyF kQXNEL+6YaLzFJTiz6yjsDU307AqoyXBFNN8yoRSbdkSTch+Mv4xxTKeaM7I36dvc+8Vf+ qsT0SqKhVRgO69c3wOLdRRiA88TFssMu+qOnjLvuiTXomXxaPJ74ASsX89juLA== 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 4SNJ8k6fLhz1M1V; Sun, 5 Nov 2023 02:19: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 3A52Jovl005405; Sun, 5 Nov 2023 02:19:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A52JolT005402; Sun, 5 Nov 2023 02:19:50 GMT (envelope-from git) Date: Sun, 5 Nov 2023 02:19:50 GMT Message-Id: <202311050219.3A52JolT005402@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: e116e040f309 - main - 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/main X-Git-Reftype: branch X-Git-Commit: e116e040f3091eca914a06dcd0bdd9f1aea23add Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=e116e040f3091eca914a06dcd0bdd9f1aea23add commit e116e040f3091eca914a06dcd0bdd9f1aea23add Author: Kyle Evans AuthorDate: 2023-11-05 02:08:36 +0000 Commit: Kyle Evans CommitDate: 2023-11-05 02:19: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 --- 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);