From 643a0b2e0b74f89c4c0e749a06cc67f748f76a8d Mon Sep 17 00:00:00 2001 From: millert Date: Fri, 3 Jan 2014 15:25:18 +0000 Subject: [PATCH] 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. --- usr.bin/whois/whois.c | 16 ++++++++-------- 1 file 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); -- 2.20.1