From nobody Tue Sep 23 12:03:46 2025 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 4cWJXz46JPz68YS3; Tue, 23 Sep 2025 12:03:47 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cWJXy6M9Yz3F18; Tue, 23 Sep 2025 12:03:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758629026; 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=gIqSm+g+tMV7X5/Htnpt4bxTQpPK60yWkWATyFChbaU=; b=y3Gykqm7IQOfUuo/gjE15A/OYySvchHloOe2fKsVbrxYwCA/buD4xC+blsMLB/MJMiapd2 2Ky1fi6zZNoZQ0gVe1aJhp7oMcyQPY9qSON1YuEtMBwZY6RXmxC3B/aoESADT1xbuYI3mW m0xiFGLFRdvwyNHoQuDpDcpw51ClkKYzOHU+uMc/MgO/Iq8UqtfM2lhQ80eFxoYFIZnS4+ B5ldALUEndxYS4KEu4CctEYRwhGSFaWTXtViM2E9Jq6eXU08fpxuNakFHpYZu5YjmbhaFG AySXYygdV9EoQPqBHlIv8AuN6LJydx2RS8QRQ9XoPJBV7tvHle4/L7rRbh2sHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758629026; 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=gIqSm+g+tMV7X5/Htnpt4bxTQpPK60yWkWATyFChbaU=; b=rPxPsiXMt90PHhtzSoyxKvgRZlrgWNwqCkgUqeyKa5koaqJWPmL4EfGZk8nlxxLvkR2+dk 6wVP/3N0YQA541l//zCKX1n9glgwIe3WqC4R0CqXv3XNjWEyux/U2s+phmTPqW6pdcmk+1 0m7bYEgiAExE5HoTyWqAqbekCNCimXvaJra0/7QEFix5vWzTz3M8W7gFAi3xFt6Tj/QM13 IDFYz6z++Y5WwQKMa5PrkUxsRB8LX7l50N5jyvooSLnzfmAn3vqCF6fcs4NvmkUVP3Df2a rwbmwfUOmJhhtvcTRGECDlqlPN9uZidH1AF9GUgn9wMku5dt4mhStjF+sAoQ1w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758629026; a=rsa-sha256; cv=none; b=NDzAsJY/Yh3w3S0TdJydMyX06WB7jHkXyp9LBYLFjb2IyN8lXwmLJ4fSW0KYQSUDucTe7/ UtwLvo+AeDXr9mmcBPwg2c1DA+qXPkeZFYe+Lkoe9nbt0ppRSRdg5/8nPV1AhlpQON98ny GRrjiQ34RzHYuf7ct9+Vc+GgmWBpL88Me5GIzDcxF9Ei3Iwk9y9ONmeK7pUYFektjsLjal KqASKAd676Kwa+79i1NoRpqOINMLe+gadnvv2jNSUZc4VsalGfR0xf/l19b51OGocaLQFn E2R2ki4uNfmsfrlKPHt33JNG0521x34icrgDCSVuclwKRhVTvGosuabLFs34tQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cWJXy5pm0zllX; Tue, 23 Sep 2025 12:03:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58NC3k5D008875; Tue, 23 Sep 2025 12:03:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58NC3kAF008872; Tue, 23 Sep 2025 12:03:46 GMT (envelope-from git) Date: Tue, 23 Sep 2025 12:03:46 GMT Message-Id: <202509231203.58NC3kAF008872@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: fda64d005e4e - stable/15 - initgroups(3): Fix return value on allocation failure 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: fda64d005e4e9d06166d38fc5e0a26c7d03e61be Auto-Submitted: auto-generated The branch stable/15 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=fda64d005e4e9d06166d38fc5e0a26c7d03e61be commit fda64d005e4e9d06166d38fc5e0a26c7d03e61be Author: Olivier Certner AuthorDate: 2025-09-16 15:52:20 +0000 Commit: Olivier Certner CommitDate: 2025-09-23 12:02:46 +0000 initgroups(3): Fix return value on allocation failure We must not return ENOMEM, but rather -1 with 'errno' set to ENOMEM, as described in the manual page and as other implementations are doing. A malloc() failure actually already sets ENOMEM for us. Add comments indicating which function set 'errno' each time we return. While here, improve style and remove useless headers. Reviewed by: kib, emaste Fixes: 54404cfb13d4 ("In preparation for raising NGROUPS and NGROUPS_MAX, ...") MFC after: 5 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52580 (cherry picked from commit 0b018cfd81d8fdd64af3fe94c6989a82c0d3afa9) --- lib/libc/gen/initgroups.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c index b6697dd7ed8f..55f17a94fa8e 100644 --- a/lib/libc/gen/initgroups.c +++ b/lib/libc/gen/initgroups.c @@ -31,11 +31,7 @@ #include -#include "namespace.h" -#include -#include "un-namespace.h" #include -#include #include #include @@ -51,12 +47,13 @@ initgroups(const char *uname, gid_t agroup) * setgroups to fail and set errno. */ ngroups_max = sysconf(_SC_NGROUPS_MAX) + 2; - if ((groups = malloc(sizeof(*groups) * ngroups_max)) == NULL) - return (ENOMEM); + groups = malloc(sizeof(*groups) * ngroups_max); + if (groups == NULL) + return (-1); /* malloc() set 'errno'. */ ngroups = (int)ngroups_max; getgrouplist(uname, agroup, groups, &ngroups); ret = setgroups(ngroups, groups); free(groups); - return (ret); + return (ret); /* setgroups() set 'errno'. */ }