From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x92f.google.com (mail-ua1-x92f.google.com [IPv6:2607:f8b0:4864:20::92f]) by sourceware.org (Postfix) with ESMTPS id 840E7385840A for ; Thu, 11 Nov 2021 13:36:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 840E7385840A Received: by mail-ua1-x92f.google.com with SMTP id l43so11869269uad.4 for ; Thu, 11 Nov 2021 05:36:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=TVDvfKdQME4aRX76RkuzwvY363Jj4PZbHCNc3P/vpsg=; b=Dw5JVycgOxoVL+TYYCfsUFBQIvuhdgLRok/rKtmzXr8Qppc9X16KeAZ59m15krTz1p Tz2Iu+zaZIZQRZMwGjZ0H5p/yAUML4Yp6baxigsAh2nujiG8fbe1DBJdqw1i4n3reSW6 fuwVTBcpknGU/HsDth5WFdvICGsoF4oxRN+7e/zCecCSrKShlMM+M9yVHykrvKwJDQFa ZJVW6y6T3KRGJe8ywq6rg0EFfWv6DWF1bycKB8JEU7wp8nHRCdWdCKrcsfotvkp0385T HLCeWdm/qF5Qjk/lrMKn/NcSaUmRxi72ID2rarMLASxSvkdGpku60zQdHpfFDZeqyZ9Z 0Jpw== X-Gm-Message-State: AOAM5311jXrh3OObYvsUQPw+0f3fBivO87pYptfq5/rSlznxdzj4zQku p5Kt7VErfvMlk7zBducrf4xXiLr1P/NfYA== X-Google-Smtp-Source: ABdhPJwJ5A/VDOvbB96Iez5GOpVYLCwZndsTSHwU1MayNaEr0+/lf6QpIo+SpIn9szUXunK/rdkGBA== X-Received: by 2002:a67:cb0c:: with SMTP id b12mr10668137vsl.13.1636637784111; Thu, 11 Nov 2021 05:36:24 -0800 (PST) Received: from ?IPV6:2804:431:c7cb:55a:48f2:1d0b:8ae8:643a? ([2804:431:c7cb:55a:48f2:1d0b:8ae8:643a]) by smtp.gmail.com with ESMTPSA id v3sm2002717vkv.19.2021.11.11.05.36.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Nov 2021 05:36:23 -0800 (PST) Message-ID: <458c6b92-0344-f1d5-748a-38208d8c5713@linaro.org> Date: Thu, 11 Nov 2021 10:36:21 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH 2/3] inet: Remove strdupa from nrl_domainname() Content-Language: en-US To: Florian Weimer , Adhemerval Zanella via Libc-alpha Cc: leonardo.macchia@gmail.com References: <20211110185832.1931688-1-adhemerval.zanella@linaro.org> <20211110185832.1931688-3-adhemerval.zanella@linaro.org> <87mtmb14wm.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87mtmb14wm.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-15.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Thu, 11 Nov 2021 13:36:26 -0000 On 11/11/2021 05:18, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> We can use the already in place scratch_buffer. >> >> Checked on x86_64-linux-gnu. >> --- >> inet/getnameinfo.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/inet/getnameinfo.c b/inet/getnameinfo.c >> index 58ebbb1154..69a94604bd 100644 >> --- a/inet/getnameinfo.c >> +++ b/inet/getnameinfo.c >> @@ -127,10 +127,10 @@ nrl_domainname (void) >> else >> { >> /* We need to preserve the hostname. */ >> - const char *hstname = strdupa (tmpbuf.data); >> - while (__gethostbyname_r (hstname, &th, >> - tmpbuf.data, >> - tmpbuf.length, >> + size_t hstnamelen = strlen (tmpbuf.data) + 1; >> + while (__gethostbyname_r (tmpbuf.data, &th, >> + tmpbuf.data + hstnamelen, >> + tmpbuf.length - hstnamelen, >> &h, &herror)) >> { >> if (herror == NETDB_INTERNAL && errno == ERANGE) > > Can you use malloc instead? scratch_buffer_grow_preserve is a bit of an > outlier in the interface. It would require to add more complexity, since now we have two allocations to handle (the hstname and the scratch_buffer) and on fast patch it would actually require a malloc call, where mostly likely it would be done in the stack fror scratch_buffer. I am not sure it is really an improvement here.