]> sourceware.org Git - glibc.git/commitdiff
hurd: fix gethostname(NULL, 0)
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 6 Sep 2017 22:51:17 +0000 (00:51 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 6 Sep 2017 22:51:17 +0000 (00:51 +0200)
* hurd/get-host.c (_hurd_get_host_config): Also check that more == 0
before assuming that the file is empty.  Avoid testing buffer content
when nread == 0.

ChangeLog
hurd/get-host.c

index 3e064fb9a9c3b72fdaa0919aa7203a0640790396..c40ee5db4f241b5d43458f4af824f689dcd151d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-09-07  Samuel Thibault  <samuel.thibault@ens-lyon.org>
+
+       * hurd/get-host.c (_hurd_get_host_config): Also check that more == 0
+       before assuming that the file is empty.  Avoid testing buffer content
+       when nread == 0.
+
 2017-09-06  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
        [BZ #18858]
index be8345fbf9d244add3ac97beba80a7de40eca482..e5d05392754d02345fd3ac033e218986646f5ed8 100644 (file)
@@ -65,7 +65,7 @@ _hurd_get_host_config (const char *item, char *buf, size_t buflen)
     }
 
   /* If the file is empty, give an empty value.  */
-  if (nread == 0)
+  if (nread == 0 && more == 0)
     {
       if (buflen != 0)
        *buf = '\0';
@@ -80,7 +80,7 @@ _hurd_get_host_config (const char *item, char *buf, size_t buflen)
   if (nread < buflen)
     buf[nread] = '\0';
   else
-    if (buf[nread - 1] != '\0')
+    if (nread != 0 && buf[nread - 1] != '\0')
       more = 1;
 
   if (more)
This page took 0.047298 seconds and 5 git commands to generate.