From patchwork Tue Jun 20 21:40:31 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: 71467 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A98153858431 for ; Tue, 20 Jun 2023 21:40:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A98153858431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687297259; bh=/y9otUxvrBNzPhVQWm8UCzj/bFRcoes4asbZBPXWMpo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=bd/vLoYvWDjjHR8sI2Bz63HUkpFeDNBs6IIHHPmMuYnfY4cuyBOmTq6xgWJbUyRTH u2uGRV1nsXZJnBtXVG0WgaMOyIlHY+ZGY+1q/6h9Yh06IKdCbgcFWCqTdMKUQdn/MR MjZYIJDyhFGCrwPCrr+nkUJfDWRoOpN/dXy22BJI= 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 DCA213858D28 for ; Tue, 20 Jun 2023 21:40:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCA213858D28 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-130-d9NDwup_PI6Hfu6RlGBBow-1; Tue, 20 Jun 2023 17:40:35 -0400 X-MC-Unique: d9NDwup_PI6Hfu6RlGBBow-1 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-39ec42c63e6so3022699b6e.0 for ; Tue, 20 Jun 2023 14:40:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687297234; x=1689889234; 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=/y9otUxvrBNzPhVQWm8UCzj/bFRcoes4asbZBPXWMpo=; b=DaY1LVaRwyLIkNLFZ60z3JWFDYd7XKJ3nE7zTJLesFaad2XaRUYMUBKZbhSLTKBpU5 JuFyV75t86lInBbYk94e3c88Qo5ljEXfpKV+/jbmE8Ak4mEBvtd5JelSev7W4HSGBM0n BzE1543Cx+Xr7hHYA5pflJOrboUGsw0qrMltv0/E6y6vwm4+oY0dtbu6Fuw1dtNtyP+h VqPH459pb0cTQ0EVMOAjxstlWiOBw7lOze47uV7+ywN/e6ICT0ioklQMPI1BOdpMlMyS NZvUWbEq7W9C+AgvXgcv6E0RRKNatlLV5+eJ6MlLjOvDZTzAqwssgjRtukPlQcUKJc87 MOpg== X-Gm-Message-State: AC+VfDxXZzvTmxuAqGS3LRd3bD7hN0NxAYDuqlP2llcEmmPoHfge2/LD +s1iU3DC3a4B68S5PS/uNMHdPfkcK/zH5x4pJI4Sog72a/5sJr4Axwh+3Mj36bL57VVLzk/y71g I03PE8R2s9ptKlGRdcmW9i/ulDJYW5eqcg5Evyo16X55O46e8SHNeCAEDF0wZJQLxZOItiRFL4I kLeXc1 X-Received: by 2002:a05:6358:cc24:b0:130:df0e:6502 with SMTP id gx36-20020a056358cc2400b00130df0e6502mr5271794rwb.32.1687297234747; Tue, 20 Jun 2023 14:40:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6WqNhY88ruQFfATAIvFInm7zKBpUP/K0E5BezRSbbtsuVfMueZZwv+nlUXawiaaHTSWlOxnA== X-Received: by 2002:a05:6358:cc24:b0:130:df0e:6502 with SMTP id gx36-20020a056358cc2400b00130df0e6502mr5271786rwb.32.1687297234463; Tue, 20 Jun 2023 14:40:34 -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 p127-20020a0dcd85000000b00568ebae9162sm694695ywd.144.2023.06.20.14.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 14:40:34 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH] getaddrinfo: Get rid of alloca Date: Tue, 20 Jun 2023 17:40:31 -0400 Message-Id: <20230620214031.1241057-1-josimmon@redhat.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use a scratch_buffer rather than alloca to avoid potential stack overflow. --- sysdeps/posix/getaddrinfo.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 0356b622be..442475d621 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -2404,22 +2404,17 @@ getaddrinfo (const char *name, const char *service, struct addrinfo *q; struct addrinfo *last = NULL; char *canonname = NULL; - bool malloc_results; size_t alloc_size = nresults * (sizeof (*results) + sizeof (size_t)); + struct scratch_buffer buf; + scratch_buffer_init (&buf); - malloc_results - = !__libc_use_alloca (alloc_size); - if (malloc_results) + if (!scratch_buffer_set_array_size (&buf, 1, alloc_size)) { - results = malloc (alloc_size); - if (results == NULL) - { - __free_in6ai (in6ai); - return EAI_MEMORY; - } + __free_in6ai (in6ai); + return EAI_MEMORY; } - else - results = alloca (alloc_size); + results = buf.data; + order = (size_t *) (results + nresults); /* Now we definitely need the interface information. */ @@ -2590,8 +2585,7 @@ getaddrinfo (const char *name, const char *service, /* Fill in the canonical name into the new first entry. */ p->ai_canonname = canonname; - if (malloc_results) - free (results); + scratch_buffer_free (&buf); } __free_in6ai (in6ai);