Index: src/usr.bin/whois/whois.c =================================================================== RCS file: /home/ncvs/src/usr.bin/whois/whois.c,v retrieving revision 1.37 diff -u -r1.37 whois.c --- src/usr.bin/whois/whois.c 29 Jun 2003 23:56:31 -0000 1.37 +++ src/usr.bin/whois/whois.c 9 Dec 2003 10:27:54 -0000 @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -262,7 +263,7 @@ { FILE *sfi, *sfo; struct addrinfo *hostres, *res; - char *buf, *host, *nhost, *p; + char *abuf, *buf, *host, *nhost, *p; int i, s; size_t c, len; @@ -287,6 +288,16 @@ fflush(sfo); nhost = NULL; while ((buf = fgetln(sfi, &len)) != NULL) { + abuf = NULL; + if ((len == 0) || !isspace(buf[len - 1])) { + abuf = calloc(1, len + 1); + if (abuf == NULL) { + errno = ENOMEM; + err(1, "reallocating"); + } + memcpy(abuf, buf, len); + buf = abuf; + } while (len > 0 && isspace((unsigned char)buf[len - 1])) buf[--len] = '\0'; printf("%.*s\n", (int)len, buf); @@ -327,6 +338,7 @@ } } } + free(abuf); } if (nhost != NULL) { whois(query, nhost, 0);