aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2017-09-07 00:51:17 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2017-09-07 00:51:17 +0200
commit507fe02799e7dbaba9ebaf3264731fc3b928ba77 (patch)
tree5573377298259c7dd56e105b725aadaaa5ccd1d2
parent7bbbb4b9f7033be9ffbaf691d886b23b363bcf53 (diff)
downloadglibc-507fe02799e7dbaba9ebaf3264731fc3b928ba77.zip
glibc-507fe02799e7dbaba9ebaf3264731fc3b928ba77.tar.gz
glibc-507fe02799e7dbaba9ebaf3264731fc3b928ba77.tar.bz2
hurd: fix gethostname(NULL, 0)
* 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.
-rw-r--r--ChangeLog6
-rw-r--r--hurd/get-host.c4
2 files changed, 8 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e064fb..c40ee5d 100644
--- 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]
diff --git a/hurd/get-host.c b/hurd/get-host.c
index be8345f..e5d0539 100644
--- a/hurd/get-host.c
+++ b/hurd/get-host.c
@@ -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)