This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] gethostid (Linux variant): Switch to struct scratch_buffer [BZ #18023]


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.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]