Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Jun 2001 16:18:29 -0400 (EDT)
From:      mike@q9media.com
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/28082: [patch] src/usr.bin/whois clean-up
Message-ID:  <200106112018.f5BKITm67332@coffee.q9media.com>

next in thread | raw e-mail | index | archive | help

>Number:         28082
>Category:       bin
>Synopsis:       [patch] src/usr.bin/whois clean-up
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 11 13:10:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Mike Barcroft
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Q9 Media
>Environment:

$FreeBSD: /c/ncvs/src/usr.bin/whois/Makefile,v 1.3 1999/11/17 19:11:51 ache Exp $
$FreeBSD: /c/ncvs/src/usr.bin/whois/whois.c,v 1.18 2001/06/01 13:43:20 ume Exp $

>Description:

The following patch has been sent to -audit.  Reviewed by mikeh and gad.
All problems brought up were resolved.


20010605 whois.patch

 o Silence warnings and set WARNS=2
 o Fix two memory leaks
 o asprint -> strdup where appropriate
 o calloc/strcpy/strcat -> aprintf
 o Convert to ANSI C to avoid having to prototype main()
 o Fix two minor tab issues

>How-To-Repeat:

	

>Fix:

Index: whois/Makefile
===================================================================
RCS file: /home/ncvs/src/usr.bin/whois/Makefile,v
retrieving revision 1.3
diff -u -r1.3 Makefile
--- whois/Makefile	1999/11/17 19:11:51	1.3
+++ whois/Makefile	2001/06/05 05:06:59
@@ -2,8 +2,8 @@
 # $FreeBSD: src/usr.bin/whois/Makefile,v 1.3 1999/11/17 19:11:51 ache Exp $
 
 PROG=	whois
+WARNS?=	2
 
-CFLAGS+=-Wall
 .if defined(SOCKS)
 CFLAGS+=-DSOCKS
 CFLAGS+=-Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dlisten=Rlisten \
Index: whois/whois.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.18
diff -u -r1.18 whois.c
--- whois/whois.c	2001/06/01 13:43:20	1.18
+++ whois/whois.c	2001/06/05 05:07:00
@@ -75,17 +75,15 @@
 #define WHOIS_INIC_FALLBACK	0x02
 #define WHOIS_QUICK		0x04
 
-static void usage __P((void));
-static void whois __P((char *, struct addrinfo *, int));
+static void	usage(void);
+static void	whois(char *, struct addrinfo *, int);
 
 int
-main(argc, argv)
-	int argc;
-	char **argv;
+main(int argc, char *argv[])
 {
 	int ch, i, j, error;
 	int use_qnichost, flags;
-	char *host;
+	const char *host;
 	char *qnichost;
 	struct addrinfo hints, *res;
 
@@ -157,10 +155,6 @@
 	}
 	while (argc--) {
 		if (use_qnichost) {
-			if (qnichost) {
-				free(qnichost);
-				qnichost = NULL;
-			}
 			for (i = j = 0; (*argv)[i]; i++) {
 				if ((*argv)[i] == '.') {
 					j = i;
@@ -168,17 +162,16 @@
 			}
 			if (j != 0) {
 				if (isdigit(*(*argv + j + 1))) {
-					(void) asprintf(&qnichost, "%s",
-					    ANICHOST);
+					qnichost = strdup(ANICHOST);
+					if (qnichost == NULL) {
+						err(1, "strdup");
+					}
 				} else {
-					qnichost = (char *) calloc(i - j
-					    + 1 + strlen(QNICHOST_TAIL),
-					    sizeof(char));
-					if (!qnichost) {
-						err(1, "calloc");
+					(void)asprintf(&qnichost, "%s%s",
+					    *argv + j + 1, QNICHOST_TAIL);
+					if (qnichost == NULL) {
+						err(1, "asprintf");
 					}
-					strcpy(qnichost, *argv + j + 1);
-					strcat(qnichost, QNICHOST_TAIL);
 				}
 
 				memset(&hints, 0, sizeof(hints));
@@ -186,10 +179,10 @@
 				hints.ai_family = AF_UNSPEC;
 				hints.ai_socktype = SOCK_STREAM;
 				error = getaddrinfo(qnichost, "whois",
-						&hints, &res);
+				    &hints, &res);
 				if (error != 0)
 					errx(EX_NOHOST, "%s: %s", qnichost,
-						gai_strerror(error));
+					   gai_strerror(error));
 			}
 		}
 		if (!qnichost) {
@@ -203,6 +196,8 @@
 					gai_strerror(error));
 		}
 
+		free(qnichost);
+		qnichost = NULL;
 		whois(*argv++, res, flags);
 		freeaddrinfo(res);
 	}
@@ -210,10 +205,7 @@
 }
 
 static void
-whois(name, res, flags)
-	char *name;
-	struct addrinfo *res;
-	int flags;
+whois(char *name, struct addrinfo *res, int flags)
 {
 	FILE *sfi, *sfo;
 	char *buf, *p, *nhost;
@@ -277,7 +269,10 @@
 	/* Do second lookup as needed */
 	if (nomatch && !nhost) {
 		(void)printf("Looking up %s at %s.\n\n", name, INICHOST);
-		nhost = INICHOST;
+		nhost = strdup(INICHOST);
+		if (nhost == NULL) {
+			err(1, "strdup");
+		}
 	}
 	if (nhost) {
 		struct addrinfo hints, *res2;
@@ -301,7 +296,7 @@
 }
 
 static void
-usage()
+usage(void)
 {
 	(void)fprintf(stderr,
 	    "usage: whois [-adgimpQrR6] [-h hostname] name ...\n");

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200106112018.f5BKITm67332>