public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
@ 2018-09-19 20:52 Florian Weimer
  2018-09-20  2:09 ` Yu, Mingli
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Weimer @ 2018-09-19 20:52 UTC (permalink / raw)
  To: Mingli Yu; +Cc: libc-alpha

Compared to the version posted on Bugzilla, I added a check on ret.  If
ret == 0 and hp == NULL, herr and errno are not necessarily valid.

Okay for master?

Thanks,
Florian

Commit message:

Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]

A NULL value can happen with certain gethostbyname_r failures.

ChangeLog entry:

2018-09-19  Mingli Yu  <Mingli.Yu@windriver.com>

	* sysdeps/unix/sysv/linux/gethostid.c (gethostid): Check for NULL
	value from gethostbyname_r.

diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c
index 2e20f034dc..ee0190e7f9 100644
--- a/sysdeps/unix/sysv/linux/gethostid.c
+++ b/sysdeps/unix/sysv/linux/gethostid.c
@@ -102,12 +102,12 @@ gethostid (void)
     {
       int ret = __gethostbyname_r (hostname, &hostbuf,
 				   tmpbuf.data, tmpbuf.length, &hp, &herr);
-      if (ret == 0)
+      if (ret == 0 && hp != NULL)
 	break;
       else
 	{
 	  /* Enlarge the buffer on ERANGE.  */
-	  if (herr == NETDB_INTERNAL && errno == ERANGE)
+	  if (ret != 0 && herr == NETDB_INTERNAL && errno == ERANGE)
 	    {
 	      if (!scratch_buffer_grow (&tmpbuf))
 		return 0;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
  2018-09-19 20:52 [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679] Florian Weimer
@ 2018-09-20  2:09 ` Yu, Mingli
  2018-09-20 10:02   ` Florian Weimer
  0 siblings, 1 reply; 3+ messages in thread
From: Yu, Mingli @ 2018-09-20  2:09 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha



On 2018年09月20日 04:51, Florian Weimer wrote:
> Compared to the version posted on Bugzilla, I added a check on ret.  If
> ret == 0 and hp == NULL, herr and errno are not necessarily valid.
>
> Okay for master?

Thanks Florian for your respond! I'm fine with your update for the patch.

Thanks,
Mingli

>
> Thanks,
> Florian
>
> Commit message:
>
> Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
>
> A NULL value can happen with certain gethostbyname_r failures.
>
> ChangeLog entry:
>
> 2018-09-19  Mingli Yu  <Mingli.Yu@windriver.com>
>
> 	* sysdeps/unix/sysv/linux/gethostid.c (gethostid): Check for NULL
> 	value from gethostbyname_r.
>
> diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c
> index 2e20f034dc..ee0190e7f9 100644
> --- a/sysdeps/unix/sysv/linux/gethostid.c
> +++ b/sysdeps/unix/sysv/linux/gethostid.c
> @@ -102,12 +102,12 @@ gethostid (void)
>       {
>         int ret = __gethostbyname_r (hostname, &hostbuf,
>   				   tmpbuf.data, tmpbuf.length, &hp, &herr);
> -      if (ret == 0)
> +      if (ret == 0 && hp != NULL)
>   	break;
>         else
>   	{
>   	  /* Enlarge the buffer on ERANGE.  */
> -	  if (herr == NETDB_INTERNAL && errno == ERANGE)
> +	  if (ret != 0 && herr == NETDB_INTERNAL && errno == ERANGE)
>   	    {
>   	      if (!scratch_buffer_grow (&tmpbuf))
>   		return 0;
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
  2018-09-20  2:09 ` Yu, Mingli
@ 2018-09-20 10:02   ` Florian Weimer
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Weimer @ 2018-09-20 10:02 UTC (permalink / raw)
  To: Yu, Mingli; +Cc: libc-alpha

* Mingli Yu:

> On 2018年09月20日 04:51, Florian Weimer wrote:
>> Compared to the version posted on Bugzilla, I added a check on ret.  If
>> ret == 0 and hp == NULL, herr and errno are not necessarily valid.
>>
>> Okay for master?
>
> Thanks Florian for your respond! I'm fine with your update for the
> patch.

Thanks, I will check it in.

Florian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-09-20 10:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-19 20:52 [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679] Florian Weimer
2018-09-20  2:09 ` Yu, Mingli
2018-09-20 10:02   ` Florian Weimer

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