This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] gethostid (Linux variant): Switch to struct scratch_buffer [BZ #18023]
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, libc-alpha at sourceware dot org
- Date: Tue, 18 Sep 2018 12:59:11 +0200
- Subject: Re: [PATCH] gethostid (Linux variant): Switch to struct scratch_buffer [BZ #18023]
- References: <20180626154633.BC8B943994575@oldenburg.str.redhat.com> <aa50fb15-99d8-28c3-d3ea-a883a8563634@linaro.org> <df00e77d-528d-e410-ecb2-7699d45ebd5d@redhat.com> <mvm4lenxemo.fsf@suse.de>
* 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?