fix out of bounds write for zero length buffer in gethostname
authorMarc André Tanner <mat@brain-dump.org>
Sun, 11 Mar 2018 08:55:06 +0000 (09:55 +0100)
committerRich Felker <dalias@aerifal.cx>
Thu, 19 Apr 2018 15:45:22 +0000 (11:45 -0400)
src/unistd/gethostname.c

index f984b7dd2f9a88dde7fb23132424f912c17bcdc0..633ef571a4011332e2b47fc14a1841e398cc792a 100644 (file)
@@ -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;
 }