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.129.124]) by sourceware.org (Postfix) with ESMTPS id 411763836E8E for ; Mon, 5 Jun 2023 13:37:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 411763836E8E 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=1685972258; 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=fT3SCqg/6oi4Am4R0jnDXF/MYzoOcsYObefwUaztwP8=; b=S5pOnISDKt0G7CpMeqW6Id6Qj4tR+uNfECf7xIsPtfs6z4yPU3bvdcxrQIfkDFdcCQuHmR GZ1kOPYjLeL+TmfClbQJ+zMo0K9Yy1eayqJih682F9xtuKrNuBkORzvP+X3U4vqi3vXNcz LerY6co1ZShDh2s/vaYRVun98Pre2vw= 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-581-JvpyV8ZzNaO9nKpl16OO1w-1; Mon, 05 Jun 2023 09:37:35 -0400 X-MC-Unique: JvpyV8ZzNaO9nKpl16OO1w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 84C93101A590; Mon, 5 Jun 2023 13:37:35 +0000 (UTC) Received: from oak (unknown [10.22.10.124]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5DCCB9E8F; Mon, 5 Jun 2023 13:37:35 +0000 (UTC) Date: Mon, 5 Jun 2023 09:37:34 -0400 From: Joe Simmons-Talbott To: Florian Weimer Cc: Joe Simmons-Talbott via Libc-alpha , Samuel Thibault , Sergey Bugaev Subject: Re: [PATCH] grantpt: Get rid of alloca Message-ID: <20230605133734.GU176347@oak> References: <20230601195817.3251303-1-josimmon@redhat.com> <87ttvmyr3q.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 In-Reply-To: <87ttvmyr3q.fsf@oldenburg.str.redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: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. Thanks, Joe > > Maybe the hurd maintainers could review this change? > > Thanks, > Florian >