Message ID | 20211110185832.1931688-3-adhemerval.zanella@linaro.org |
---|---|
State | Superseded |
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> 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 C77563857C73 for <patchwork@sourceware.org>; Wed, 10 Nov 2021 19:01:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C77563857C73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636570864; bh=bn8duwf7MhrxzfsyuKb4ArEKmpoBfuSWldolaBEQa2o=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=PEp1z7yvo4qR95hiZ5Jj/xDKHACLDMgHNkJlsuf2L4LYLZygj6TTDu80Q7gl+aeYH QgQ7m+xgn94Sq8stuGAuv2IH2kgodl2ztINRkAmzL0b4Te8HXcnzbrkGOAp9Bc1Imr t00HjhMFGuyRFxN1ntEs/oZXGoXJK2L0wNMArD/Y= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ua1-x930.google.com (mail-ua1-x930.google.com [IPv6:2607:f8b0:4864:20::930]) by sourceware.org (Postfix) with ESMTPS id B85823857C52 for <libc-alpha@sourceware.org>; Wed, 10 Nov 2021 18:58:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B85823857C52 Received: by mail-ua1-x930.google.com with SMTP id ay21so6852819uab.12 for <libc-alpha@sourceware.org>; Wed, 10 Nov 2021 10:58:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bn8duwf7MhrxzfsyuKb4ArEKmpoBfuSWldolaBEQa2o=; b=L1DeEefqfyRUD7CqnjKk99IVXypJgJxvgjCaJuecrt1WkNH0x/5Vt4qVm2jjlkdnYp kU4YRNCR9jONQ46v3CR7C/V/7t+vDj+yu/v1lePF4uGrmGpqqAexZ//UezMI7acjKlWr h4SJUZsmYVwd8Uw1iS+6N2h5aYhtqdtl1OBwVLqDkIehL/wduAf2217pT4ztmRWRmabi py9wTBEZMenZ6gdFXXysCEzeAZNfObTSQtEgeq13EebYHDU5DixvzH9YqOQP09ijPj0P K6jZjvC5R5MNd92h3f5AoVqb+pbETqvS3x312TaPPCLMsTGPonUUGGvBNpdOkvos0gEg Q0lA== X-Gm-Message-State: AOAM530IfnQ6J6FdfUVl58OpzLatPjmKpd+VG3KxHesTl+Ts+jDXOVg2 obthgOA+wfHmr3zTooQsJ1PG+cHkG3/Z2w== X-Google-Smtp-Source: ABdhPJylCnrDGDh1Dsm4rdeokdVG2W3Za5Md8wiApuaFr3bXKN9bwOsp8lbWRNS6nAv2eGlHc2kmOg== X-Received: by 2002:a67:c993:: with SMTP id y19mr1413788vsk.36.1636570718765; Wed, 10 Nov 2021 10:58:38 -0800 (PST) Received: from birita.. ([2804:431:c7cb:55a:73fa:8bad:ab14:14a3]) by smtp.gmail.com with ESMTPSA id r20sm518149vkq.15.2021.11.10.10.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 10:58:38 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 2/3] inet: Remove strdupa from nrl_domainname() Date: Wed, 10 Nov 2021 15:58:31 -0300 Message-Id: <20211110185832.1931688-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211110185832.1931688-1-adhemerval.zanella@linaro.org> References: <20211110185832.1931688-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Adhemerval Zanella <adhemerval.zanella@linaro.org> Cc: leonardo.macchia@gmail.com Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Fixes for getnameinfo() with NI_NOFQDN
|
|
Checks
Context | Check | Description |
---|---|---|
dj/TryBot-apply_patch | success | Patch applied to master at the time it was sent |
Commit Message
Adhemerval Zanella Netto
Nov. 10, 2021, 6:58 p.m. UTC
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(-)
Comments
* 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. Thanks, Florian
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.
* Adhemerval Zanella: > 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. Fair enough, let's keep the code simple. Thanks, Florian
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)