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 8397F3858D33 for ; Mon, 15 May 2023 19:09:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8397F3858D33 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=1684177763; 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=VhSqSaF3Ox8xdARAZvaM5ueENGFzzodQa+rru7WKJpk=; b=dIshNZNUHoa+cwiUx0g+Z6P2ADYZ/Z3RVBf5jCX48OK1vVzMMcktah9Zi/Nfjor/8i5VPt 9znl8N9b+L5jKkkqU8x2AL2WkrxOUUt1qQehCE56YfTyEGVX26XkfgshJJKox6Lxg3W3BO CGvcI/dD65vHnmlJcXpqRBd/Fo/kyGg= 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-88-BE3xLXUfPfKU5M5AsX0qXQ-1; Mon, 15 May 2023 15:09:21 -0400 X-MC-Unique: BE3xLXUfPfKU5M5AsX0qXQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7479A857DEC; Mon, 15 May 2023 19:09:21 +0000 (UTC) Received: from oak (unknown [10.22.32.82]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 594F514152F6; Mon, 15 May 2023 19:09:21 +0000 (UTC) Date: Mon, 15 May 2023 15:09:20 -0400 From: Joe Simmons-Talbott To: Adhemerval Zanella Netto Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] setsourcefilter: Use malloc() rather than alloca(). Message-ID: <20230515190920.GC176347@oak> References: <20230511150915.2468745-1-josimmon@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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.4 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,RCVD_IN_MSPIKE_H2,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, May 15, 2023 at 03:35:10PM -0300, Adhemerval Zanella Netto wrote: > > > On 11/05/23 12:09, Joe Simmons-Talbott via Libc-alpha wrote: > > To prevent possible stack overflow use malloc() rather than alloca(). > > --- > > sysdeps/unix/sysv/linux/setsourcefilter.c | 22 ++++++---------------- > > 1 file changed, 6 insertions(+), 16 deletions(-) > > > > diff --git a/sysdeps/unix/sysv/linux/setsourcefilter.c b/sysdeps/unix/sysv/linux/setsourcefilter.c > > index 538f4de696..6678572968 100644 > > --- a/sysdeps/unix/sysv/linux/setsourcefilter.c > > +++ b/sysdeps/unix/sysv/linux/setsourcefilter.c > > @@ -16,7 +16,6 @@ > > License along with the GNU C Library; if not, see > > . */ > > > > -#include > > #include > > #include > > #include > > @@ -34,17 +33,11 @@ setsourcefilter (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. */ > > size_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; > > - } > > + gf = (struct group_filter *) malloc (needed); > > + if (gf == NULL) > > + return -1; > > > > gf->gf_interface = interface; > > memcpy (&gf->gf_group, group, grouplen); > > @@ -63,12 +56,9 @@ setsourcefilter (int s, uint32_t interface, const struct sockaddr *group, > > else > > result = __setsockopt (s, sol, MCAST_MSFILTER, gf, needed); > > > > - if (! use_alloca) > > - { > > - int save_errno = errno; > > - free (gf); > > - __set_errno (save_errno); > > - } > > + int save_errno = errno; > > + free (gf); > > + __set_errno (save_errno); > > > > return result; > > } > > free now must preserve errno (check 69fda43b8dd795c3658869633ca0708ed3134006), > so there is no need to save/restore it. The rest looks ok for me. > Thanks. Fixed in v2. Joe