From nobody Fri Oct 10 17:16:22 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 4cjtgq5r9Vz6Bcgr; Fri, 10 Oct 2025 17:16:23 +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 4cjtgp68Hjz3g9G; Fri, 10 Oct 2025 17:16:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760116582; 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=QOvrOCOeQO6KN6AuE+5iMFJdlYW/fKgCXDK+29oDH6c=; b=DoYs19aCL6Jv0PFLf3qypqbnci/oNcz+ui1uRJRo3bAZS0DAtED8Kni4/kM1IjAyELMCJa aUBryWksyFS/o5Jr8sYVsRIdnS0DO8Xu9x8Bs+HpWOMSqGlVWRiChDM7H4ItmjQonEpOwh /Y4ZdI70X792kygvQcs8LBW/MkhtHPFe3AGp+Oxs2tM85W8/CMS59DdcYwLMCs7nJtUu0r movRtBBBnL5fwe8+l+VKKeLL9JwNoQeoP06TU3VReMNNYdKGab9imEMTcgSrHv99xZOzta aFP/dc/jDCl7jEyUnSjXFpg6aZSzgjg0OSn5V+19H7VGzzo4iSxXzX/HYBQ8ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760116582; 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=QOvrOCOeQO6KN6AuE+5iMFJdlYW/fKgCXDK+29oDH6c=; b=uSW7y3iGnMf2kpg+Ziba+wcXsWFYaGHz6NtS5cxyP7RtBsJskzvPVZrtzyWKPk4BlNSevX zx5vZsbuU1ZKgBIbPnpUBiV7KjtEOESPVgJNl2tD+5h4UQCq4eTfvH4jnp1ttKIv22hhQS GILoKIM6TQ636JyOpbTdLg1FMH0nk/lZyy8nvKQNPYutk2VFN8K7ieOTKnNue6YQhxDXow R/OeoovHzLCyZtzWaoyxZlMkddlfckEDmn4+C0odEa8OO1m0SThWyyGSN+k7pGKIQPpvNg y5zQKb1isHTnXj/FF4P37PSaQp3M0ZqpuwQzmhUjZT+DO4y0XRK4o2PsNSMNAg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1760116582; a=rsa-sha256; cv=none; b=t09rkZErZ63f7fMTspGE7CRkmWZlTLHzs4bmf7dooW4owtHCJrnCcXq9HRf+2NsDFaWGUE +B7yZEYZlWlgI5NpubREwdG8XGXR5vbYjSZsh26dgj/huJj78gg1Qb3YRXp7eImkeCaI+7 VyiROxkkkaXQkTQVVvgZETdpZ0v2bAlz//PR+E4D/vWLGvgJJvoK4ddXXqcJtjj4W56f0z onQnlw/wuzR8vYNxvSRLLbq1mCoqe1R5RaWTlW0pIF41eOmAkIA/ypm1ALbrWyqMcd77NU rPooqPXnATSiNqAIMJYRiiuL5bw74TFezVVHaP2+Gl07ciGSEPNiYnOQqjXnbA== 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 4cjtgp5kFvz1BN4; Fri, 10 Oct 2025 17:16:22 +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 59AHGM5Q009286; Fri, 10 Oct 2025 17:16:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59AHGMZk009283; Fri, 10 Oct 2025 17:16:22 GMT (envelope-from git) Date: Fri, 10 Oct 2025 17:16:22 GMT Message-Id: <202510101716.59AHGMZk009283@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: faa9bcee1540 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: faa9bcee15407bf8fc0985fbc759897290d79ca5 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=faa9bcee15407bf8fc0985fbc759897290d79ca5 commit faa9bcee15407bf8fc0985fbc759897290d79ca5 Author: Olivier Certner AuthorDate: 2025-09-16 15:52:20 +0000 Commit: Olivier Certner CommitDate: 2025-10-10 17:15:57 +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 6e417d6a62ed..9dd162978a52 100644 --- a/lib/libc/gen/initgroups.c +++ b/lib/libc/gen/initgroups.c @@ -33,11 +33,7 @@ __SCCSID("@(#)initgroups.c 8.1 (Berkeley) 6/4/93"); #include -#include "namespace.h" -#include -#include "un-namespace.h" #include -#include #include #include @@ -53,12 +49,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'. */ }