From patchwork Wed May 31 13:01:22 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: 1788346 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=tnSWW+wq; 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 4QWV1l2cs0z20Py for ; Wed, 31 May 2023 23:08:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 618183858C30 for ; Wed, 31 May 2023 13:08:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 618183858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685538489; bh=ExMkVszSXEPvkONfbTWi7hEllw+QcvXoVVr5zXppbW4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=tnSWW+wq2RBTQtKjhekDR2IBXfXkk8ltXRi59J27NZJpUCqPm6FKU7KaIGHW0tPf4 PaRdQ3UwgDqxGC2eebX/nXcibw0VdCNJ1fGiyDC84BwFLreBwjHXrwIFARwAtPehwN ORG65dHoGXbwxBOrLR7zjnwC88Mz7HCL0mheVbOg= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id CDFAC3858035 for ; Wed, 31 May 2023 13:07:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDFAC3858035 Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-zIsfBPGtOfaDLs4qDKVoAQ-1; Wed, 31 May 2023 09:01:29 -0400 X-MC-Unique: zIsfBPGtOfaDLs4qDKVoAQ-1 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-39a013fbee8so2768232b6e.0 for ; Wed, 31 May 2023 06:01:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685538087; x=1688130087; 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=ExMkVszSXEPvkONfbTWi7hEllw+QcvXoVVr5zXppbW4=; b=CjcXYa7kbF57BAp5OHWQyMVvH9SMIVaqXHOmOsbixjQIqQn9p2qswuhZZ11yV1iSVO 2Fp2jDyr2Ee1eQ4r/IAwUGP9gTBa57mjWiHSJjgOcG+nfVFz3KeitVDPsIc/2LiFo9O2 jBhkkhgdWVLuosiacr8D6q3sMtRCy5hudJS9SYLqHO8eGv5vC5WKIVxDE3fbt1iLpSnK +LAzjk2BzgmxtOye2OWt6SbOpdGsXAg0s2TlTAAdWDgp0iWLKBE9a/1IA13OCP3v8NsC JT8ZfSYEu2oOIxuUSw3uWNYXz2flxxU43WEcZJYFZuGfoH/WxUqmHsSNJ8WyaqWYyafR 9EJg== X-Gm-Message-State: AC+VfDzwvzOdbYO4HCClj525e9OaCBpKhXhuq0SAGCNCZ0GplMlxd7tL +V28g+8fe9ZPMJRhh/SY/hbaj8WwsFU/CXuSYMKAG6lQzuSCcYj0wNR26vm9ZOfxSey5W5J0j8L ObonroUg4JqfmYuvh1fmfw7OK7zJl9khDxaIngwtEo/peCd9OR7rOQDa4nb9/3en2Js8O4qF4U8 5MNY+d X-Received: by 2002:a05:6808:1983:b0:397:fe89:202c with SMTP id bj3-20020a056808198300b00397fe89202cmr3901584oib.42.1685538087442; Wed, 31 May 2023 06:01:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5KimOL+3iw/rjX5VAFCJRzIUyubon4NqMe8dAkREyyF4ElKSfUIYCQW8nobA9gtqKTzZO9EQ== X-Received: by 2002:a05:6808:1983:b0:397:fe89:202c with SMTP id bj3-20020a056808198300b00397fe89202cmr3901506oib.42.1685538086722; Wed, 31 May 2023 06:01:26 -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 mm16-20020a0562145e9000b00621253d19f9sm1502296qvb.98.2023.05.31.06.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 06:01:26 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] check_native: Get rid of alloca Date: Wed, 31 May 2023 09:01:22 -0400 Message-Id: <20230531130122.174601-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, 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 malloc rather than alloca to avoid potential stack overflow. --- sysdeps/unix/sysv/linux/check_native.c | 27 +++++++++----------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/sysdeps/unix/sysv/linux/check_native.c b/sysdeps/unix/sysv/linux/check_native.c index 34876ca624..45b328f240 100644 --- a/sysdeps/unix/sysv/linux/check_native.c +++ b/sysdeps/unix/sysv/linux/check_native.c @@ -37,6 +37,12 @@ #include "netlinkaccess.h" +static void +ifree (char **ptr) +{ + free (*ptr); +} + void __check_native (uint32_t a1_index, int *a1_native, uint32_t a2_index, int *a2_native) @@ -48,7 +54,6 @@ __check_native (uint32_t a1_index, int *a1_native, nladdr.nl_family = AF_NETLINK; socklen_t addr_len = sizeof (nladdr); - bool use_malloc = false; if (fd < 0) return; @@ -82,24 +87,13 @@ __check_native (uint32_t a1_index, int *a1_native, nladdr.nl_family = AF_NETLINK; #ifdef PAGE_SIZE - /* Help the compiler optimize out the malloc call if PAGE_SIZE - is constant and smaller or equal to PTHREAD_STACK_MIN/4. */ const size_t buf_size = PAGE_SIZE; #else const size_t buf_size = __getpagesize (); #endif - char *buf; - - if (__libc_use_alloca (buf_size)) - buf = alloca (buf_size); - else - { - buf = malloc (buf_size); - if (buf != NULL) - use_malloc = true; - else - goto out; - } + char *buf __attribute__ ((__cleanup__ (ifree))) = malloc (buf_size); + if (buf == NULL) + goto out; struct iovec iov = { buf, buf_size }; @@ -170,7 +164,4 @@ __check_native (uint32_t a1_index, int *a1_native, out: __close_nocancel_nostatus (fd); - - if (use_malloc) - free (buf); }