From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from egyptian.ash.relay.mailchannels.net (egyptian.ash.relay.mailchannels.net [23.83.222.56]) by sourceware.org (Postfix) with ESMTPS id E9BF23858416 for ; Tue, 6 Jun 2023 06:14:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E9BF23858416 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 1893A502573; Tue, 6 Jun 2023 06:14:48 +0000 (UTC) Received: from pdx1-sub0-mail-a283.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A0DA65024AD; Tue, 6 Jun 2023 06:14:47 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1686032087; a=rsa-sha256; cv=none; b=7mlxA1wMfRmpp/ws8uwQBf2cGVy8XMyYBSNAldxyFLa683d9ErL7aFDtZ0PcOr2bBsqpht LQzRViHSVfOaZHpBnTwhU9nWJI3zIl8GxeOhMzjx6reRref5iAIeBKPkyy6ZPa7N9+Kmlm TCrmj9gnmRykwq+o57KoOxRuvB4cPSe8JA4vJN+YrCCvO3/oqULpD5/AmmMoFxyp9xZRRa W7LXVMd1GAC/bZTvqjBJlonxsMYgXYdPv+28h/D0j+ROp3QNoH323zv7X1viiw5bN2gUWJ Ypc60FyPDeBcv2E9j+mvyOwNAnlyufrQEvliTVszs4NlivI6yq4JZ9N8V1fFTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1686032087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc: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=5t03uI9AdYuQHalSEpgc1+ia00gv0k5cCQ0pvT/FKHM=; b=dqZcJ0wGmKizkXzvt5VP01x5Gw8303F8+WxjIq1yoGZ6tYstFG8H8eht+eFTCTwUW5hRI0 OYLyKKfd0EeKSBmmxkZcxW6SC6DXlqoDaAKjGjGpjYxs2Z1sxn63Va/CafWoA8uyUqUpji WOqFcG2HH4BgMM9RS5/L/ldDOALDeTj3y674rsdxON7tlqXSLSfxwNxmGkiat16eq++mzK pNOo7fLYrDlwHw/unAD9THRCalTfN2KuxQ2CH+IddvWf1OAqjNU74hzlsiIx3HbyYujoT1 FWC7ANXnF8UlWAd3DgLFQ/FSTBJenxtsaU3YQ/zNwHXAfeNG629YXpqWHlzZ3Q== ARC-Authentication-Results: i=1; rspamd-5f966895c-w7ff7; 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-Cold-Shade: 6a5e7d991da2c05c_1686032087932_2688780399 X-MC-Loop-Signature: 1686032087932:2272722396 X-MC-Ingress-Time: 1686032087931 Received: from pdx1-sub0-mail-a283.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.107.49.247 (trex/6.8.1); Tue, 06 Jun 2023 06:14:47 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-02-142-113-138-85.dsl.bell.ca [142.113.138.85]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a283.dreamhost.com (Postfix) with ESMTPSA id 4Qb0Yy6whtzKm; Mon, 5 Jun 2023 23:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1686032087; bh=5t03uI9AdYuQHalSEpgc1+ia00gv0k5cCQ0pvT/FKHM=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=VETndSY+ihxKKI80o7D/+A4rtB8+ZpFy12KMRL9K1cY03Ltml7yAs6etlkfvXViI1 d5bWyGn3jhtwaXb4gZqS2cjI8DuJ+ILMh0YsEPQCgBVLNVZ7yy4Ljm5bG0zZ8gv02n pJXke4xfacmrIsiJgXvL9IeQm7Tafy2pAGh1+bPVbQnU4bXV7BdI0hOt8OuzcGbmDB WtDzzD4N5RCPOvxrUdVLWOUCwvw2BSJR7n/fWKuqoTUFL4Z0DnClZuUgZJ0O0YWO7T IPhckp17dJFGPpikCYxPr9yP8gWVzCMX95s6dWRiNdGK1yTNhDPoLUvQ5BHbBCKRia WK2OffHWroRag== Message-ID: Date: Tue, 6 Jun 2023 02:14:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] grantpt: Get rid of alloca Content-Language: en-US To: Joe Simmons-Talbott , Adhemerval Zanella Netto Cc: Florian Weimer , Joe Simmons-Talbott via Libc-alpha , Samuel Thibault , Sergey Bugaev References: <20230601195817.3251303-1-josimmon@redhat.com> <87ttvmyr3q.fsf@oldenburg.str.redhat.com> <20230605133734.GU176347@oak> <20230605220239.GV176347@oak> From: Siddhesh Poyarekar In-Reply-To: <20230605220239.GV176347@oak> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3037.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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-06-05 18:02, Joe Simmons-Talbott wrote: > On Mon, Jun 05, 2023 at 03:14:06PM -0300, Adhemerval Zanella Netto wrote: >> >> >> On 05/06/23 10:37, Joe Simmons-Talbott via Libc-alpha wrote: >>> On Mon, Jun 05, 2023 at 03:29:45PM +0200, Florian Weimer wrote: >>>> * Joe Simmons-Talbott via Libc-alpha: >>>> >>>>> Replace alloca with a scratch_buffer to avoid potential stack overflows. >>>>> --- >>>>> sysdeps/unix/grantpt.c | 12 +++++++++++- >>>>> 1 file changed, 11 insertions(+), 1 deletion(-) >>>>> >>>>> diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c >>>>> index 38fce52576..e5d2390bf2 100644 >>>>> --- a/sysdeps/unix/grantpt.c >>>>> +++ b/sysdeps/unix/grantpt.c >>>>> @@ -20,6 +20,7 @@ >>>>> #include >>>>> #include >>>>> #include >>>>> +#include >>>>> #include >>>>> #include >>>>> #include >>>>> @@ -147,7 +148,14 @@ grantpt (int fd) >>>>> /* `sysconf' does not support _SC_GETGR_R_SIZE_MAX. >>>>> Try a moderate value. */ >>>>> grbuflen = 1024; >>>>> - grtmpbuf = (char *) __alloca (grbuflen); >>>>> + struct scratch_buffer sbuf; >>>>> + scratch_buffer_init (&sbuf); >>>>> + if (!scratch_buffer_set_array_size (&sbuf, 1, grbuflen)) >>>>> + { >>>>> + retval -1; >>>>> + goto cleanup; >>>>> + } >>>>> + grtmpbuf = sbuf.data; >>>>> __getgrnam_r (TTY_GROUP, &grbuf, grtmpbuf, grbuflen, &p); >>>>> if (p != NULL) >>>>> tty_gid = p->gr_gid; >>>>> @@ -255,6 +263,8 @@ grantpt (int fd) >>>>> if (buf != _buf) >>>>> free (buf); >>>>> >>>>> + scratch_buffer_free(sbuf); >>>>> + >>>>> return retval; >>>>> } >>>>> libc_hidden_def (grantpt) >>>> >>>> How did you test this? This code is only used on Hurd due to the >>>> override in sysdeps/unix/sysv/linux/grantpt.c. >>> >>> The only testing I did was a 'make && make check' on x86_64 and i686 linux. >> >> You will need to build for i686-gnu (Hurd) to actually enable this code. Which >> leads to another, which Siddheash has brough, which is --enable-pt_chown does >> make sense to be provided as a configure switch. Yeah I looked at the code again and perhaps it's something for Samuel to think about. We don't seem to have target-specific configure options, so it's a nop for Linux. > I tested this patch today with build-many-glibcs.py for i686-gnu and it > passed 'make check'. Does your second sentence mean that I needed to > pass '--enable-pt_chown' to configure for the test build? Not really, the code you're changing is outside of HAVE_PT_CHOWN, so you're good to go I think. I'd wait for Samuel to ack this since this is exclusively hurd code. Thanks, Sid