From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by sourceware.org (Postfix) with ESMTPS id D0FBD3858D20 for ; Wed, 31 May 2023 12:37:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0FBD3858D20 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-oo1-xc35.google.com with SMTP id 006d021491bc7-557d69340e9so3215349eaf.3 for ; Wed, 31 May 2023 05:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685536638; x=1688128638; 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=RBRkHAUEWkbR2zozVXImZNJWP6YWdODEqYl+eYZ5jyc=; b=OFmG8ZEJhMsCRQgToUJ23gW6jKdRT9seBAXvEloAY6T20OYMqsHk+54WpDB/uBphi1 Jxks9hykwdalPqdiFG7qnG+9N0naDkD7rCVTEFmmpLwJmx7uyrXzg9ZFG93jDYWeD0tu I8EdmiXQIuQpdrrAqVflb7GSsMAFCF7qtXvpFHFFSOVcbxFZqiPkoThmMZaMlra3gZ7R YvAKnQJGiStrdEJeOh3zybwh+ioR3hwaAGdIqFnLCC/hE5ekn+ZijaSRq3DIdBRhiCJP BGMtvGL2r55bXXEtv7XC5hehJ/tbr5vs22mMbCGoXyQFXw2EIT+/PG/2st+J+MUZnUVJ UJdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685536638; x=1688128638; 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=RBRkHAUEWkbR2zozVXImZNJWP6YWdODEqYl+eYZ5jyc=; b=fATAMQtorm9SnjCW6OaO3CqjcJg4TGp15fQRjUsqdFaP1PMDqbEL1JPETi8Rfs9BW8 4RAGvIK60hQlB9YSvKv//OvRinhhGEBXkLFb5oxFj8gjh+YkE9OEkZjzW8EHIS4zfG8N 2wLjQptbboS8e2+YmW61O8pZM5TgCzVg+f8c3PMVArZhppN67XqVqYAJQJvmqsK+hkK9 ZQ5oAJhZiiw57pG8ws4SpiAEddGn+rbWCmPC4+JX4JzNXoksIZfJVZj7hfwHFTI5DbaU iFoheMVAeOKYWPlVuM7gjgoAfcPG1Nyo2TFRYpGdRMSOJ6Vu0/zlKfxWzRCDeCmCn/8v 1vRw== X-Gm-Message-State: AC+VfDzikdyLs7L/cFJGXV45SUWKFHDta8FnIqnotPwCifWK1tUGLwtN Qz+r4hxKJEcyX4lDY3BK8rERmQ== X-Google-Smtp-Source: ACHHUZ7OL4VzlQXEj8XIxHhIcZSs8X47vAwnNIR87vGFmR5OkHUsv82sS7bF4HFsbT5+fQLYkzLRSg== X-Received: by 2002:a4a:2cc6:0:b0:555:ccd3:6e88 with SMTP id o189-20020a4a2cc6000000b00555ccd36e88mr2461523ooo.6.1685536638131; Wed, 31 May 2023 05:37:18 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c1:4dd5:94e0:97d1:f451:639a? ([2804:1b3:a7c1:4dd5:94e0:97d1:f451:639a]) by smtp.gmail.com with ESMTPSA id j12-20020a4ac54c000000b0054cbf3be7e1sm6088569ooq.32.2023.05.31.05.37.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 May 2023 05:37:17 -0700 (PDT) Message-ID: <6d5ebc02-0b95-ef6a-d01b-edfcfed92a8b@linaro.org> Date: Wed, 31 May 2023 09:37:15 -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] getipv4sourcefilter: Get rid of alloca Content-Language: en-US To: Joe Simmons-Talbott , libc-alpha@sourceware.org References: <20230530183255.637210-1-josimmon@redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20230530183255.637210-1-josimmon@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 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:32, 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/getipv4sourcefilter.c | 24 ++++++------------- > 1 file changed, 7 insertions(+), 17 deletions(-) > > diff --git a/sysdeps/unix/sysv/linux/getipv4sourcefilter.c b/sysdeps/unix/sysv/linux/getipv4sourcefilter.c > index 8a367b1048..ce72becead 100644 > --- a/sysdeps/unix/sysv/linux/getipv4sourcefilter.c > +++ b/sysdeps/unix/sysv/linux/getipv4sourcefilter.c > @@ -16,9 +16,9 @@ > License along with the GNU C Library; if not, see > . */ > > -#include > #include > #include > +#include > #include > #include > #include > @@ -33,17 +33,12 @@ getipv4sourcefilter (int s, struct in_addr interface, struct in_addr group, > /* We have to create an struct ip_msfilter object which we can pass > to the kernel. */ > socklen_t needed = IP_MSFILTER_SIZE (*numsrc); > - int use_alloca = __libc_use_alloca (needed); > > - struct ip_msfilter *imsf; > - if (use_alloca) > - imsf = (struct ip_msfilter *) alloca (needed); > - else > - { > - imsf = (struct ip_msfilter *) malloc (needed); > - if (imsf == NULL) > - return -1; > - } > + struct scratch_buffer buf; > + scratch_buffer_init (&buf); > + if (!scratch_buffer_set_array_size (&buf, 1, needed)) > + return -1; > + struct ip_msfilter *imsf = buf.data; > > imsf->imsf_multiaddr = group; > imsf->imsf_interface = interface; > @@ -61,12 +56,7 @@ getipv4sourcefilter (int s, struct in_addr interface, struct in_addr group, > *numsrc = imsf->imsf_numsrc; > } > > - if (! use_alloca) > - { > - int save_errno = errno; > - free (imsf); > - __set_errno (save_errno); > - } > + scratch_buffer_free (&buf); > > return result; > }