From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 245273858C39 for ; Wed, 31 May 2023 12:27:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 245273858C39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3982f09df74so3540037b6e.0 for ; Wed, 31 May 2023 05:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685536053; x=1688128053; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ujEEhQy+t9wEvzaO+0AhybmI0A3CC5ULE0CdVjCuiSI=; b=YZcBlSER4tuC6aE4R03ccBeb1Nq1a+vhOow+ig829nVEJ8fAQEiBlE20TirL9cD022 n0UNziCT+J+77CTsrx/AaHI8Ra++bz0yabQ9m4Ca6Lmci3f+mcTdYCCflQwN9u31GxiN FvrZtwEqH1CbwQl4W4dmnzhenS/09PH0c1K9X3zNAnZe4lQPOIXxHzQPyyDtqj6K+9Go 1FkktpG6NbrApt2sVziuHD5W2aT95wxx07AqldzeLOmcCbAC+w9iflXhLHDYPrKm4G2t WmFBPNHso7bTiUdFvX6R1iFgNF9LflOgeBEdL/D+0sqyTTIn24KLAJIdS+luvPtNe45T gS/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685536053; x=1688128053; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ujEEhQy+t9wEvzaO+0AhybmI0A3CC5ULE0CdVjCuiSI=; b=fHbU+RCdUf8jG9zYFOnYSv+z+M3X0IWjdYf0wMVe5gHi28dMEJtY0o7J0EWcl5LxbR vcuAw07NQ4WrhzxrTqC0rlc33C9DDahKWnIBj90lWxuohPjkJnZ5pbEtNdDPXT0AyeW7 XdAbgeLwxXyfytME2XFkrZ2/c5lG96erd7msBeMkd6FTMfXk4Z0H8cbU3dlOHFSSKF0u IlNQbIL0lLXsPgLuDPXOdQcujN4CMvMiZD5fvA43Cu4LdXXowDhtO/XzSYHbAwnjkkfF Pkai/kHIVhzyT/nlsl2X2xcni2/RcKKBgtNVMfbpFkatE2zd7aILw/p9G0onSVb8jnL3 9P7w== X-Gm-Message-State: AC+VfDxaN6azM6Ai4Zc8gcLrWoNZbtFpieGAjKwMP7nxfTis0L4EJ+j1 ChD7lo8VLf9Bz8T25hIHWSDWdSKOZZ1JHUrAejIVnQ== X-Google-Smtp-Source: ACHHUZ4c7QljaTyJd17GPQGKR7toQuk/d7R/3jCdZ92ilz2fD+atMoziAINzjzF6+mUPtGtn8OB2EA== X-Received: by 2002:aca:e044:0:b0:397:fe55:36bb with SMTP id x65-20020acae044000000b00397fe5536bbmr3632955oig.46.1685536053433; Wed, 31 May 2023 05:27:33 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:4dd5:80c6:51f7:4cf7:20d3? ([2804:1b3:a7c1:4dd5:80c6:51f7:4cf7:20d3]) by smtp.gmail.com with ESMTPSA id bh24-20020a056808181800b0039819ef73e7sm461950oib.2.2023.05.31.05.27.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 May 2023 05:27:32 -0700 (PDT) Message-ID: <505c2a47-fd63-0c2b-87bb-97f954f415b9@linaro.org> Date: Wed, 31 May 2023 09:27:30 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.1 Subject: Re: [PATCH] getsourcefilter: Get rid of alloca. Content-Language: en-US To: Joe Simmons-Talbott , libc-alpha@sourceware.org References: <20230530181340.3926125-1-josimmon@redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230530181340.3926125-1-josimmon@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 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 > --- > 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; > }