From patchwork Tue May 30 18:32:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 1787855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=RFeQhKPa; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW1HV4TW0z20Pc for ; Wed, 31 May 2023 04:33:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CAC23857706 for ; Tue, 30 May 2023 18:33:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CAC23857706 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685471604; bh=Yi3/Jd9+XR7U1K3t+84Ip33gF0DH5Hr+JzBF8VHf2OA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=RFeQhKPadRzn8hZFL6C4FuXmrlCB1ZGzjmumWUjcdpdvDyqDl/TyRLNbYVaoi6t9c EPhE3GWJ2Riib91MdnKjLSyew0Fi/0D1utjjKayig18GpLIhgz88pI0pzyAHKQzHg3 2gjjPTrzuh8P2uFyCmZdH4bU+221TQDsAmfp6wGU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 CFD853858D20 for ; Tue, 30 May 2023 18:33:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFD853858D20 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-z3-zk1VmPtuHIc9RsNs67A-1; Tue, 30 May 2023 14:32:59 -0400 X-MC-Unique: z3-zk1VmPtuHIc9RsNs67A-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6262360e603so15468306d6.2 for ; Tue, 30 May 2023 11:32:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685471578; x=1688063578; 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=Yi3/Jd9+XR7U1K3t+84Ip33gF0DH5Hr+JzBF8VHf2OA=; b=io2eZlXS6sB1e61ju+MSHaNq4K7w2gtXUVYysVBETIGj/vaiYNokArM4AiNcSK6m28 3RjVqQAuPm5lSn1R35iir21MFITFI/GXdbV7xdfjahJccg+2DYOWBdiDYJMbZza+RFZ8 1FU6tVa3fbWWhYiXuqlHx83miY///I8dv9KjU+dOoMNAaHsj6UESiE3VDHXnu+uNzBWO bwVpSEO6OlFWn0SjsPlTjSTpKqtU5iHViLAztKhA3LfYEPimlfmo3fj0Yj7iwFxMepWW 5cR1bQSpkClmsCa7dFOKeVqrndyTp3C/kZ/3txdf8RjO4BsuNXov6ibu2yuLhWheFk7B wzsg== X-Gm-Message-State: AC+VfDw8iQGd3Ae4JPVXEixIpcQXR4yIT22ngq019EK2ZmjvMv9j2Nw0 iS5VtzluMcwnh6R4FQpghH11E1dez6q0oI3uAsj2KGE26VrVakbnhGL8iLq5yiWDbme8s4EYSbe 1HM9lnHO3avWh8eo8XOr9wqvZWYXHpxdzAvOlHI03Q8lHq2AXsP28WI5qMe7TqPoiOr2N540UBh IcEG53 X-Received: by 2002:a05:6214:da5:b0:626:2e8f:b50 with SMTP id h5-20020a0562140da500b006262e8f0b50mr3593151qvh.10.1685471578295; Tue, 30 May 2023 11:32:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6R79ikYyvIRjuxOweYLp6smAjKLgSyo2wDnIJRREciaSbISn4hRdnTUXYZYtiaMgk+QSyrrQ== X-Received: by 2002:a05:6214:da5:b0:626:2e8f:b50 with SMTP id h5-20020a0562140da500b006262e8f0b50mr3593131qvh.10.1685471578010; Tue, 30 May 2023 11:32:58 -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 m24-20020a05620a13b800b0075ca93fd90dsm4147537qki.45.2023.05.30.11.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 11:32:57 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] getipv4sourcefilter: Get rid of alloca Date: Tue, 30 May 2023 14:32:55 -0400 Message-Id: <20230530183255.637210-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 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Use a scratch_buffer rather than alloca to avoid potential stack overflows. 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; }