about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2018-03-11 09:55:06 +0100
committerRich Felker <dalias@aerifal.cx>2018-04-19 11:45:22 -0400
commit3f6dc30470d5751b83645df180a60cad3e7907ef (patch)
tree04f22e86401260a554ed742fbd07b8a56b05dd4f /src
parent0b80a7b0404b6e49b0b724e3e3fe0ed5af3b08ef (diff)
downloadmusl-3f6dc30470d5751b83645df180a60cad3e7907ef.tar.gz
musl-3f6dc30470d5751b83645df180a60cad3e7907ef.tar.xz
musl-3f6dc30470d5751b83645df180a60cad3e7907ef.zip
fix out of bounds write for zero length buffer in gethostname
Diffstat (limited to 'src')
-rw-r--r--src/unistd/gethostname.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/unistd/gethostname.c b/src/unistd/gethostname.c
index f984b7dd..633ef571 100644
--- a/src/unistd/gethostname.c
+++ b/src/unistd/gethostname.c
@@ -8,6 +8,6 @@ int gethostname(char *name, size_t len)
 	if (uname(&uts)) return -1;
 	if (len > sizeof uts.nodename) len = sizeof uts.nodename;
 	for (i=0; i<len && (name[i] = uts.nodename[i]); i++);
-	if (i==len) name[i-1] = 0;
+	if (i && i==len) name[i-1] = 0;
 	return 0;
 }