fix out of bounds write for zero length buffer in gethostname

This commit is contained in:
Marc André Tanner 2018-03-11 09:55:06 +01:00 committed by Rich Felker
parent 0b80a7b040
commit 3f6dc30470
1 changed files with 1 additions and 1 deletions

View 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;
}