getenv can return NULL
authoraland <aland>
Mon, 7 Jul 2003 15:47:54 +0000 (15:47 +0000)
committeraland <aland>
Mon, 7 Jul 2003 15:47:54 +0000 (15:47 +0000)
Patch from Steve G

src/lib/missing.c

index fa970eb..1415fdb 100644 (file)
@@ -91,7 +91,7 @@ int gethostname(char *name, int len)
        char            *h;
 
        h = getenv("HOSTNAME");
-       if (strlen(h) + 1 > len)
+       if (!h || (strlen(h) + 1 > len))
                return -1;
        strcpy(name, h);
        return 0;