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 D866E3857C4F for ; Thu, 1 Jun 2023 14:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D866E3857C4F 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=1685629285; 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=blQDOTLlxX41f+rXnPSUAj00MdhoEGCg85clqmKr+Ew=; b=XlEiPx9XB2w1bLFwMOlPJ6snMXGpNExFkx8BN2RFAOa3uaZLnpD+x5BZh2nTXayz3yUF/x YxjNBi5FmOeWDGH0eWOw4U7XADoDV8V1nkDiaKua590KFHVNh9UOsX2bY7w167+RIngA6R wBt8MEVV1BD3lbWeSrWMcjyDwLVboAs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-480-ltbqPdGpNUeLCE-Xsv2CvA-1; Thu, 01 Jun 2023 10:21:24 -0400 X-MC-Unique: ltbqPdGpNUeLCE-Xsv2CvA-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 405381C09045; Thu, 1 Jun 2023 14:21:24 +0000 (UTC) Received: from oak (unknown [10.22.10.124]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 24DDDC33E88; Thu, 1 Jun 2023 14:21:24 +0000 (UTC) Date: Thu, 1 Jun 2023 10:21:22 -0400 From: Joe Simmons-Talbott To: Adhemerval Zanella Netto Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] getsourcefilter: Get rid of alloca. Message-ID: <20230601142122.GT176347@oak> References: <20230530181340.3926125-1-josimmon@redhat.com> <505c2a47-fd63-0c2b-87bb-97f954f415b9@linaro.org> MIME-Version: 1.0 In-Reply-To: <505c2a47-fd63-0c2b-87bb-97f954f415b9@linaro.org> 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=-12.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 Wed, May 31, 2023 at 09:27:30AM -0300, Adhemerval Zanella Netto wrote: > > > On 30/05/23 15:13, Joe Simmons-Talbott via Libc-alpha wrote: > > Use a scratch_buffer rather than alloca to avoid potential stack > > overflows. > > LGTM, thanks. > > Reviewed-by: Adhemerval Zanella Thanks for the review. Would you mind committing this please? Thanks, Joe > > > --- > > sysdeps/unix/sysv/linux/getsourcefilter.c | 24 +++++++---------------- > > 1 file changed, 7 insertions(+), 17 deletions(-) > > > > diff --git a/sysdeps/unix/sysv/linux/getsourcefilter.c b/sysdeps/unix/sysv/linux/getsourcefilter.c > > index b9ba58c23a..461ad889a9 100644 > > --- a/sysdeps/unix/sysv/linux/getsourcefilter.c > > +++ b/sysdeps/unix/sysv/linux/getsourcefilter.c > > @@ -16,10 +16,10 @@ > > License along with the GNU C Library; if not, see > > . */ > > > > -#include > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -95,17 +95,12 @@ getsourcefilter (int s, uint32_t interface, const struct sockaddr *group, > > /* We have to create an struct ip_msfilter object which we can pass > > to the kernel. */ > > socklen_t needed = GROUP_FILTER_SIZE (*numsrc); > > - int use_alloca = __libc_use_alloca (needed); > > > > - struct group_filter *gf; > > - if (use_alloca) > > - gf = (struct group_filter *) alloca (needed); > > - else > > - { > > - gf = (struct group_filter *) malloc (needed); > > - if (gf == NULL) > > - return -1; > > - } > > + struct scratch_buffer buf; > > + scratch_buffer_init (&buf); > > + if (!scratch_buffer_set_array_size (&buf, 1, needed)) > > + return -1; > > + struct group_filter *gf = buf.data; > > > > gf->gf_interface = interface; > > memcpy (&gf->gf_group, group, grouplen); > > @@ -135,12 +130,7 @@ getsourcefilter (int s, uint32_t interface, const struct sockaddr *group, > > } > > } > > > > - if (! use_alloca) > > - { > > - int save_errno = errno; > > - free (gf); > > - __set_errno (save_errno); > > - } > > + scratch_buffer_free (&buf); > > > > return result; > > } >