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 ABC923858C5E for ; Tue, 30 May 2023 18:13:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABC923858C5E 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=1685470425; 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: content-transfer-encoding:content-transfer-encoding; bh=soiOGfRiV+cnTKTXS2KZc6d/b1xFprag8lItIgSwMyY=; b=Y5ynfgUxpkCxedKWQsESyPTEfTI0vuARrfJlBEZQHoyErbiTBSM1yop8J2Fqa3GHRqj01/ tXFAdFXD0boKSVeRPSCVE/fF88mmhTs/iIxkuKJKQuoZlfRrRcM0N4/WWd3FU9rUG3J1JU nOUk23BIBa1V+KauTyT4s4/8D/Dc1zs= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-924-DetFPZ6CdKCjOe_tcA-1; Tue, 30 May 2023 14:13:44 -0400 X-MC-Unique: 924-DetFPZ6CdKCjOe_tcA-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-62627366ebeso13408816d6.3 for ; Tue, 30 May 2023 11:13:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685470423; x=1688062423; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=soiOGfRiV+cnTKTXS2KZc6d/b1xFprag8lItIgSwMyY=; b=XRYriP1S0bBUwX0hFTZ+POoOCsYm3bxiC/RgmW8WyJxWcW/TMPsTf1mok3E/dI5ql1 aELaNp/WAy5cAOqkThJ2iYDKQykpqRfSuMpCs3KjlYzXipfpaU6BCoXeY/l8ojd3Ye7J w+QQRdzx9WWAtAXpfsox7NrBPrGQe4af0Fvf9SqlQvOXFlg9v8hhWKOkPT4YGWekMh7d A4+5bBV+K1Hcvh17Uex7sOS3maej8YTu4G4cGyHe44G0igN2HEoUcz3K2hymJm3pgdO6 5NlGvtPGUlMO4BIGjVk2Ew00tMctDDRS9N5XTZwMUWiWT8MkVrNdrmleFz4gvp2bUiSN 3rww== X-Gm-Message-State: AC+VfDyuUu1+qnAsgIWKPV2dThK/TSMVzLG5h635fRLHGOMpURANp71+ ceZFsNF5yTnt1xiQ793/owPHR5Kq28QtaZr1IMcbT3LEyMA4hZllo7ZuuiL/6BENzF2BRRdSVmk 0MWfNXBZ8l1fbXW2JIepVy2deU0xfx1FSsidpffE68gG6+afSIVsXuyddrbumk+Xr77M+JiMSGa 5VYvfi X-Received: by 2002:ad4:5d6c:0:b0:621:7241:df33 with SMTP id fn12-20020ad45d6c000000b006217241df33mr3730329qvb.0.1685470423349; Tue, 30 May 2023 11:13:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eUw/MeypFyhU0GKv2ZGhIohg3Ix0/d075f8i7bxIxpLdfl2z8AWWzc99WF9ONRtgYawvRew== X-Received: by 2002:ad4:5d6c:0:b0:621:7241:df33 with SMTP id fn12-20020ad45d6c000000b006217241df33mr3730303qvb.0.1685470423036; Tue, 30 May 2023 11:13:43 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id a4-20020a05620a124400b0075b1c6f9628sm4279771qkl.71.2023.05.30.11.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 11:13:42 -0700 (PDT) From: Joe Simmons-Talbott To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] getsourcefilter: Get rid of alloca. Date: Tue, 30 May 2023 14:13:40 -0400 Message-Id: <20230530181340.3926125-1-josimmon@redhat.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.3 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: Use a scratch_buffer rather than alloca to avoid potential stack overflows. --- 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; } -- 2.39.2