diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2014-01-03 15:25:19 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2014-01-03 15:25:19 +0000 |
commit | 135d1d914dba7d441473e68c3238d45c10dd4571 (patch) | |
tree | 6da1c089c944cb7edf26614a3e9e5317d70a4cdf | |
parent | fd39cd4631c3fbb414284ae678d63c8e35b4580b (diff) |
The whois() function is called in a loop so make sure we close the
socket to the whois server before returning. Adapted from a diff
from Loganaden Velvindron.
-rw-r--r-- | usr.bin/whois/whois.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c index 1cce389aedd..b3613338926 100644 --- a/usr.bin/whois/whois.c +++ b/usr.bin/whois/whois.c @@ -1,4 +1,4 @@ -/* $OpenBSD: whois.c,v 1.45 2013/11/25 18:06:32 deraadt Exp $ */ +/* $OpenBSD: whois.c,v 1.46 2014/01/03 15:25:18 millert Exp $ */ /* * Copyright (c) 1980, 1993 @@ -149,7 +149,7 @@ main(int argc, char *argv[]) int whois(const char *query, const char *server, const char *port, int flags) { - FILE *sfi, *sfo; + FILE *fp; char *buf, *p, *nhost, *nbuf = NULL; size_t len; int i, s, error; @@ -204,14 +204,13 @@ whois(const char *query, const char *server, const char *port, int flags) else fmt = "%s\r\n"; - sfi = fdopen(s, "r"); - sfo = fdopen(s, "w"); - if (sfi == NULL || sfo == NULL) + fp = fdopen(s, "r+"); + if (fp == NULL) err(1, "fdopen"); - fprintf(sfo, fmt, query); - fflush(sfo); + fprintf(fp, fmt, query); + fflush(fp); nhost = NULL; - while ((buf = fgetln(sfi, &len)) != NULL) { + while ((buf = fgetln(fp, &len)) != NULL) { p = buf + len - 1; if (isspace((unsigned char)*p)) { do @@ -252,6 +251,7 @@ whois(const char *query, const char *server, const char *port, int flags) } } } + fclose(fp); if (nbuf != NULL) free(nbuf); |