[PATCH] gethostid (Linux variant): Switch to struct scratch_buffer [BZ #18023]
Florian Weimer
fw@deneb.enyo.de
Tue Sep 18 10:59:00 GMT 2018
* Andreas Schwab:
> On Jun 26 2018, Florian Weimer <fweimer@redhat.com> wrote:
>
>> @@ -88,29 +88,43 @@ gethostid (void)
>> return id;
>> }
>>
>> - /* Getting from the file was not successful. An intelligent guess for
>> - a unique number of a host is its IP address. Return this. */
>> + /* Getting from the file was not successful. An intelligent guess
>> + for a unique number of a host is its IP address. To get the IP
>> + address we need to know the host name. */
>> if (__gethostname (hostname, MAXHOSTNAMELEN) < 0 || hostname[0] == '\0')
>> /* This also fails. Return and arbitrary value. */
>> return 0;
>>
>> - buflen = 1024;
>> - buffer = __alloca (buflen);
>> -
>> - /* To get the IP address we need to know the host name. */
>> - while (__gethostbyname_r (hostname, &hostbuf, buffer, buflen, &hp, &herr)
>> - != 0
>> - || hp == NULL)
>> - if (herr != NETDB_INTERNAL || errno != ERANGE)
>> - return 0;
>> - else
>> - /* Enlarge buffer. */
>> - buffer = extend_alloca (buffer, buflen, 2 * buflen);
>> + /* Determine the IP address of the host name. */
>> + struct scratch_buffer tmpbuf;
>> + scratch_buffer_init (&tmpbuf);
>> + while (true)
>> + {
>> + int ret = __gethostbyname_r (hostname, &hostbuf,
>> + tmpbuf.data, tmpbuf.length, &hp, &herr);
>> + if (ret == 0)
>> + break;
>
> That fails to handle hp == NULL any more, see bug 23679.
Oops. Do you want me to write a patch?
More information about the Libc-alpha
mailing list