From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C048E3858D20 for ; Mon, 5 Jun 2023 22:02:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C048E3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686002564; 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: in-reply-to:in-reply-to:references:references; bh=RJU/IpF7EqwohSLyQ40/GzE1kAFpWAJRAUh/vryQW5c=; b=iIY3ND0Q5U55nMKP7ncl4KUAspogYT1z/8/r/LOjxWl2kw+kZF1Gm+aEnPLMsBuS4Q94O1 d4JwlmismwNCpkyQAAMZH5oRAzkBJbNg65xYBVMaXL8ELH5s96lG2BiOip5uxZM5NdwlaZ 8tIw8AIPsFPXa+QpHmgrwyBPzGHflxM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-652-9wy6YINIMO-4Yf2CSZ-pLQ-1; Mon, 05 Jun 2023 18:02:41 -0400 X-MC-Unique: 9wy6YINIMO-4Yf2CSZ-pLQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 14D75101A593; Mon, 5 Jun 2023 22:02:41 +0000 (UTC) Received: from oak (unknown [10.22.10.124]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B7BC7C1603B; Mon, 5 Jun 2023 22:02:40 +0000 (UTC) Date: Mon, 5 Jun 2023 18:02:39 -0400 From: Joe Simmons-Talbott To: Adhemerval Zanella Netto Cc: Florian Weimer , Siddhesh Poyarekar , Joe Simmons-Talbott via Libc-alpha , Samuel Thibault , Sergey Bugaev Subject: Re: [PATCH] grantpt: Get rid of alloca Message-ID: <20230605220239.GV176347@oak> References: <20230601195817.3251303-1-josimmon@redhat.com> <87ttvmyr3q.fsf@oldenburg.str.redhat.com> <20230605133734.GU176347@oak> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,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 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. 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? Thanks, Joe