From nobody Wed Sep 17 12:19:15 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 4cRd9b60PZz67Hwg; Wed, 17 Sep 2025 12:19:15 +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 4cRd9b1Wllz3W98; Wed, 17 Sep 2025 12:19:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758111555; 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=1wpl+NUW4cCp3kpMmoIGsBE2uXCXCSy04aKH4xNAnww=; b=LlRBrme24hJH6Tk9WPd4QjotxToC3bv5ZzNZ6kZaXYWSZ9HLZ0BMKUSAErhAGU41kcOLyr DtYOu0ei4x7IGNM5Z97smNqOU3UAUHZS75lq5odwzcznsrEu/p53rwfBFYw/pcR+1Sf6u+ NiZpmelMz6VV+8mrsIa2ml4S8ynKvJGfH5Xl9UZXzHiVCgFI3Sn4tneHj5PSRetwKi37ZN S2ybwNVy34zR9ZL6c4vnCTkEzYP/89Wo9dzk1EjYcq+qmIaovesDKNRCfTsZO44RTo9gk3 So0ebadpkQzJINX5E1zTItySGYZwYpp03BHfA3xGPeLFwjIL0ComYHFIJFMGEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758111555; 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=1wpl+NUW4cCp3kpMmoIGsBE2uXCXCSy04aKH4xNAnww=; b=GqTbyDlJUFB/p2GcNfjlNwnveVterawn9/qOg80WW2w1Byo05fmQqEsWGNRsszg0LTt5Nc ImSqsBEHCRQISWcPVPOqDt2UrQrAzIwQ+I44JcV81t87XWHoZuUb8HsnQy580h6LCfcOE6 DO4cM7W6yMGxvVsSMj5mm13nsflHeQYCFzWKk/+82qbz1D4tAUYQcGvcjIkXdY9fc3WzMP 4xSeH5YY2oRd9i1XiZnO7Jf4+VhTtA8uWwCk5FbLaF6fDfcxv3oWltGMiUZfIfUGxB9m9i usaisveKm3Pv2DXG5okRcEXMjAEgkzwz7YIzClz0pVt87E7T0X/pRTV2aNubmQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758111555; a=rsa-sha256; cv=none; b=rqdbfE+Ymdg2VhmZoyVY2M0d33Ag856G4NdT1+HJLew/tPOHODK6GYc5RPUh8xcbFCwL7n RS1rU7+Ow499BhGh8yJTn78LIJfSjEL97wx5w0Sg+tQg23ukP6bYXds7+CgT9Bu0qJK0Z8 mqImiQesnq/DhBbmO5uctnq0pirUaAZucFBwuj+Buob4ZL8S6Esgu//2iTXQji+yliMpYU XlbxKEc4QaY55jXgPW/lnKirrUbt61eMPV05WkXrMvD1FlMp7Q4i4Luqg4BL1N76KUzYbo UlgZs7PXr3x+kTYR62kxar3hPlKlXQlZgIQptlMXBl+/xDUmoCQjTGJ5MhO8yQ== 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 4cRd9b10n1z9G6; Wed, 17 Sep 2025 12:19:15 +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 58HCJF2e086053; Wed, 17 Sep 2025 12:19:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58HCJF90086050; Wed, 17 Sep 2025 12:19:15 GMT (envelope-from git) Date: Wed, 17 Sep 2025 12:19:15 GMT Message-Id: <202509171219.58HCJF90086050@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 0b018cfd81d8 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 0b018cfd81d8fdd64af3fe94c6989a82c0d3afa9 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=0b018cfd81d8fdd64af3fe94c6989a82c0d3afa9 commit 0b018cfd81d8fdd64af3fe94c6989a82c0d3afa9 Author: Olivier Certner AuthorDate: 2025-09-16 15:52:20 +0000 Commit: Olivier Certner CommitDate: 2025-09-17 12:16:06 +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 --- 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'. */ }