diff --git a/lib/util/gethostname.c b/lib/util/gethostname.c index 7f24458d6..a10243f39 100644 --- a/lib/util/gethostname.c +++ b/lib/util/gethostname.c @@ -42,7 +42,7 @@ sudo_gethostname_v1(void) hname = malloc(host_name_max + 1); if (hname != NULL) { - if (gethostname(hname, host_name_max + 1) == 0) { + if (gethostname(hname, host_name_max + 1) == 0 && *hname != '\0') { /* Old gethostname() may not NUL-terminate if there is no room. */ hname[host_name_max] = '\0'; } else {