public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: Florian Weimer <fweimer@redhat.com>
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	 libc-alpha@sourceware.org
Subject: Re: [PATCH] gethostid (Linux variant): Switch to struct scratch_buffer [BZ #18023]
Date: Tue, 18 Sep 2018 10:51:00 -0000	[thread overview]
Message-ID: <mvm4lenxemo.fsf@suse.de> (raw)
In-Reply-To: <df00e77d-528d-e410-ecb2-7699d45ebd5d@redhat.com> (Florian Weimer's message of "Tue, 26 Jun 2018 19:33:23 +0200")

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."

  parent reply	other threads:[~2018-09-18 10:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-26 15:46 Florian Weimer
2018-06-26 16:58 ` Adhemerval Zanella
2018-06-26 17:33   ` Florian Weimer
2018-06-26 17:52     ` Adhemerval Zanella
2018-09-18 10:51     ` Andreas Schwab [this message]
2018-09-18 10:59       ` Florian Weimer
2018-09-18 12:09         ` Andreas Schwab
2018-09-18 12:32           ` Florian Weimer
2018-06-26 18:16 ` DJ Delorie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mvm4lenxemo.fsf@suse.de \
    --to=schwab@suse.de \
    --cc=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).