From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from beige.elm.relay.mailchannels.net (beige.elm.relay.mailchannels.net [23.83.212.16]) by sourceware.org (Postfix) with ESMTPS id 25A833858D3C for ; Wed, 1 Mar 2023 18:20:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25A833858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 9EAEE3E1951; Wed, 1 Mar 2023 18:20:24 +0000 (UTC) Received: from pdx1-sub0-mail-a304.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 23AF23E0624; Wed, 1 Mar 2023 18:20:24 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1677694824; a=rsa-sha256; cv=none; b=OGlv6lpHMiCabwwm87UtVP4CUSqdoml7B4ePQI9DGP1nfFNZg5Sg7zvuzdLUXcV0vDYBQz tgnQVfZBzbK6Nyuue1XBGsDIP4XNbvmMSws1kHDWDNOY8Tr2UpVQsRr0HTgUgIfGcct0tj jiSY309JYkPq74Z8dGYDTRaPS9ksF0eKmjwr3NdPf9Ypm0o8LKKu5Sdbyhm4PHJPwW7u9t DfpgjJYODeWrhGoAy1LR7wI6O4a0+ZS5+JiuLb0vPZr5h6d0jdrnqd4Cs4EZeuUs1PMzAh oa1MI66p4KM89vGreOmdK2aeV6q5R0eT4fCSbHHQAk3m2tDS03vJc1hyFTSNMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1677694824; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ae061Y7rh5mnl3k4zWmEDM1C+8duepJfuAsfLA/SoH8=; b=IHJZPY7kqIzKPCW/Ph5FbKsfQo6fCS/UT7bWsA8sDn8Vrj6ZdHcjv39oYJyZxXwWVZ8DZd QDEkdN8UJey3NOn4CW4VrvPi61EodIfdO9TuxPmVb5RTDZsKBHO8ucs70pZ+5I1+YNNb+l 2QMVBAbB9sT84lEcNYpDqjv6vAqk0XRZSoSItAlsMBvkc5gd/IghrualfWpYyS6Bwp2CSF yvh/FUXcLHHjeKR+x+pthNPOPcQXggSSnf1i5AgiV0pdlI0a6vogbQpBKp3KJB4xzIf5XK DgTBl/zLXAIb5+hVZfRnj3P0XP0YrZwaP6ADyVdoa/M7+8DzGk9+OvkHNulU8g== ARC-Authentication-Results: i=1; rspamd-69778c65cd-nq2v6; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Left-Cold: 431b5de0482eab09_1677694824395_2608693491 X-MC-Loop-Signature: 1677694824394:3298897786 X-MC-Ingress-Time: 1677694824394 Received: from pdx1-sub0-mail-a304.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.123.200.78 (trex/6.7.2); Wed, 01 Mar 2023 18:20:24 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-09-174-91-45-153.dsl.bell.ca [174.91.45.153]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a304.dreamhost.com (Postfix) with ESMTPSA id 4PRjFz3qL0z1F; Wed, 1 Mar 2023 10:20:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1677694823; bh=hFCIQ+NQLclnQYBQou3HVOpfkRwKjSNuHWrTgkE/5+A=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=cBCHbEPmVBitFKyJd4ncRVcxzLT06czVabRPhtmGNPu6v4h7Yvx8xrW90X5ny0PSP Kbd/awzl+SyyzVtrrCHX0/jEHzFHyp7kR4l9Q4FA96ViGU+yqC66VNCFdK5e0VJFpZ W+YckupS342nv7S/VC27D+ipagiqt8hzlSfvjqGSf2jKsUhTqJp9/Y0DvxSmun6WQB 6iH90woNyaps3GDdYod/+pHL1uarx3Ii3TDSB3G9E/909LYzhFyBsv1oOGjTGei5lj WmY/9+b4RaiKBk8OPq412yc/PxP+qJyOpowio34aeN8qy2UH/btENhtqYqc2HrQNKl 5EnwuhQP8blrw== Message-ID: <3e3a4797-501d-3df7-c69f-9a715f3f3e0c@gotplt.org> Date: Wed, 1 Mar 2023 13:20:22 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] gshadow: Matching sgetsgent, sgetsgent_r ERANGE handling (bug 30151) To: Florian Weimer , libc-alpha@sourceware.org References: <875ybvs98d.fsf@oldenburg.str.redhat.com> Content-Language: en-US From: Siddhesh Poyarekar In-Reply-To: <875ybvs98d.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3037.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-02-21 03:39, Florian Weimer via Libc-alpha wrote: > Before this change, sgetsgent_r did not set errno to ERNAGE, but s/ERNAGE/ERANGE/ > sgetsgent only checked errno, not the return value from sgetsgent_r. > Consequently, sgetsgent did not detect any error, and reported > success to the caller, without initializing the struct sgrp object > whose address was returned. > > This commit changes sgetsgent_r to set errno as well. This avoids > similar issues in applications which only change errno. ... which only *check* errno? The patch itself is fine. Reviewed-by: Siddhesh Poyarekar > > Tested on x86_64-linux-gnu. > > --- > gshadow/Makefile | 2 +- > gshadow/sgetsgent_r.c | 5 +++- > gshadow/tst-sgetsgent.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 74 insertions(+), 2 deletions(-) > > diff --git a/gshadow/Makefile b/gshadow/Makefile > index 796fbbf473..a95524593a 100644 > --- a/gshadow/Makefile > +++ b/gshadow/Makefile > @@ -26,7 +26,7 @@ headers = gshadow.h > routines = getsgent getsgnam sgetsgent fgetsgent putsgent \ > getsgent_r getsgnam_r sgetsgent_r fgetsgent_r > > -tests = tst-gshadow tst-putsgent tst-fgetsgent_r > +tests = tst-gshadow tst-putsgent tst-fgetsgent_r tst-sgetsgent > > CFLAGS-getsgent_r.c += -fexceptions > CFLAGS-getsgent.c += -fexceptions > diff --git a/gshadow/sgetsgent_r.c b/gshadow/sgetsgent_r.c > index ea085e91d7..c75624e1f7 100644 > --- a/gshadow/sgetsgent_r.c > +++ b/gshadow/sgetsgent_r.c > @@ -61,7 +61,10 @@ __sgetsgent_r (const char *string, struct sgrp *resbuf, char *buffer, > buffer[buflen - 1] = '\0'; > sp = strncpy (buffer, string, buflen); > if (buffer[buflen - 1] != '\0') > - return ERANGE; > + { > + __set_errno (ERANGE); > + return ERANGE; > + } > } > else > sp = (char *) string; > diff --git a/gshadow/tst-sgetsgent.c b/gshadow/tst-sgetsgent.c > new file mode 100644 > index 0000000000..0370c10fd0 > --- /dev/null > +++ b/gshadow/tst-sgetsgent.c > @@ -0,0 +1,69 @@ > +/* Test large input for sgetsgent (bug 30151). > + Copyright (C) 2023 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int > +do_test (void) > +{ > + /* Create a shadow group with 1000 members. */ > + struct xmemstream mem; > + xopen_memstream (&mem); > + const char *passwd = "k+zD0nucwfxAo3sw1NXUj6K5vt5M16+X0TVGdE1uFvq5R8V7efJ"; > + fprintf (mem.out, "group-name:%s::m0", passwd); > + for (int i = 1; i < 1000; ++i) > + fprintf (mem.out, ",m%d", i); > + xfclose_memstream (&mem); > + > + /* Call sgetsgent. */ > + char *input = mem.buffer; > + struct sgrp *e = sgetsgent (input); > + TEST_VERIFY_EXIT (e != NULL); > + TEST_COMPARE_STRING (e->sg_namp, "group-name"); > + TEST_COMPARE_STRING (e->sg_passwd, passwd); > + /* No administrators. */ > + TEST_COMPARE_STRING (e->sg_adm[0], NULL); > + /* Check the members list. */ > + for (int i = 0; i < 1000; ++i) > + { > + char *member = xasprintf ("m%d", i); > + TEST_COMPARE_STRING (e->sg_mem[i], member); > + free (member); > + } > + TEST_COMPARE_STRING (e->sg_mem[1000], NULL); > + > + /* Check that putsgent brings back the input string. */ > + xopen_memstream (&mem); > + TEST_COMPARE (putsgent (e, mem.out), 0); > + xfclose_memstream (&mem); > + /* Compare without the trailing '\n' that putsgent added. */ > + TEST_COMPARE (mem.buffer[mem.length - 1], '\n'); > + mem.buffer[mem.length - 1] = '\0'; > + TEST_COMPARE_STRING (mem.buffer, input); > + > + free (mem.buffer); > + free (input); > + return 0; > +} > + > +#include > > base-commit: 8b014a1b1f7aee1e3348db108aeea396359d481e >