From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 F22763858437 for ; Tue, 8 Mar 2022 03:53:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F22763858437 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-107-WwHkb-sCOXCda44a5V23dQ-1; Mon, 07 Mar 2022 22:53:52 -0500 X-MC-Unique: WwHkb-sCOXCda44a5V23dQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 864828031E1; Tue, 8 Mar 2022 03:53:51 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-4.rdu2.redhat.com [10.10.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5547BE2FA; Tue, 8 Mar 2022 03:53:51 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 2283rojj277227; Mon, 7 Mar 2022 22:53:50 -0500 From: DJ Delorie To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v2 2/3] inet: Remove strdupa from nrl_domainname() In-Reply-To: <20211210110733.1499984-3-adhemerval.zanella@linaro.org> (message from Adhemerval Zanella via Libc-alpha on Fri, 10 Dec 2021 08:07:32 -0300) Date: Mon, 07 Mar 2022 22:53:50 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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.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: Tue, 08 Mar 2022 03:53:57 -0000 Adhemerval Zanella via Libc-alpha writes: > else > { > /* We need to preserve the hostname. */ > - const char *hstname = strdupa (tmpbuf->data); Would have copied tmpbuf->data to the stack, and used it.. > - while (__gethostbyname_r (hstname, &th, > - tmpbuf->data, > - tmpbuf->length, > + size_t hstnamelen = strlen (tmpbuf->data) + 1; Count tmpbuf->data, include the trailing NUL. Ok. > + while (__gethostbyname_r (tmpbuf->data, &th, > + tmpbuf->data + hstnamelen, > + tmpbuf->length - hstnamelen, > &h, &herror)) But requires more buffer space in tmpbuf->data, so offset. Ok. > { > if (herror == NETDB_INTERNAL && errno == ERANGE) > { > - if (!scratch_buffer_grow (tmpbuf)) > + if (!scratch_buffer_grow_preserve (tmpbuf)) This ensures that the hostname in tmpbuf->data is preserved, although it ALSO preserves the "grown" space if we have to grow twice. Oh well, rare. Ok. LGTM Reviewed-by: DJ Delorie