]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
inet: Remove strdupa from nrl_domainname()
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 10 Nov 2021 18:26:52 +0000 (15:26 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 8 Mar 2022 15:51:29 +0000 (12:51 -0300)
We can use the already in place scratch_buffer.

Checked on x86_64-linux-gnu.

Reviewed-by: DJ Delorie <dj@redhat.com>
inet/getnameinfo.c

index 5965912c9e74cd122f689076d6295a2c04cdd627..d3387dd16a1f0bf0155ffff5d74c3aa175c816b0 100644 (file)
@@ -118,15 +118,15 @@ nrl_domainname_core (struct scratch_buffer *tmpbuf)
       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)
                {
-                 if (!scratch_buffer_grow (tmpbuf))
+                 if (!scratch_buffer_grow_preserve (tmpbuf))
                    return;
                }
              else