From mike@coffee.q9media.com  Mon Jun 11 13:07:52 2001
Return-Path: <mike@coffee.q9media.com>
Received: from coffee.q9media.com (coffee.q9media.com [216.94.229.19])
	by hub.freebsd.org (Postfix) with ESMTP id D728937B405
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 11 Jun 2001 13:07:51 -0700 (PDT)
	(envelope-from mike@coffee.q9media.com)
Received: (from mike@localhost)
	by coffee.q9media.com (8.11.2/8.11.2) id f5BKITm67332;
	Mon, 11 Jun 2001 16:18:29 -0400 (EDT)
	(envelope-from mike)
Message-Id: <200106112018.f5BKITm67332@coffee.q9media.com>
Date: Mon, 11 Jun 2001 16:18:29 -0400 (EDT)
From: mike@q9media.com
Reply-To: mike@q9media.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] src/usr.bin/whois clean-up
X-Send-Pr-Version: 3.2

>Number:         28082
>Category:       bin
>Synopsis:       [patch] src/usr.bin/whois clean-up
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 11 13:10:01 PDT 2001
>Closed-Date:    Thu Jun 21 18:52:49 PDT 2001
>Last-Modified:  Thu Jun 21 18:53:55 PDT 2001
>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:

From: Dima Dorfman <dima@unixfreak.org>
To: mike@q9media.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/28082: [patch] src/usr.bin/whois clean-up 
Date: Mon, 11 Jun 2001 20:38:19 -0700

 mike@q9media.com writes:
 >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()
 
 I don't think this is a good reason to ANSIify something, especially
 since gcc no longer complains about that.
 
 					Dima Dorfman
 					dima@unixfreak.org

From: Mike Barcroft <mike@q9media.com>
To: Dima Dorfman <dima@unixfreak.org>
Cc: <FreeBSD-gnats-submit@freebsd.org>
Subject: Re: bin/28082: [patch] src/usr.bin/whois clean-up 
Date: Tue, 12 Jun 2001 14:58:09 -0400

 On 6/11/01 11:38 PM, Dima Dorfman at dima@unixfreak.org wrote:
 
 > mike@q9media.com writes:
 >> 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()
 > 
 > I don't think this is a good reason to ANSIify something, especially
 > since gcc no longer complains about that.
 
 Would you not agree that prototyping main() is evil? :)  Also, was the
 change to gcc also applied to -stable.  Eventually this change will be MFC.
 
 I recall David saying something about it only being applied to the current
 verion of gcc, and future versions may not have it.  I would hate to
 introduce something that could result in future breakage, as a result of a
 new gcc import.
 
 My goal was to take a more proactive step towards current style(9)
 conventions.  Although style(9) recommends staying with current conventions
 unless you're changing 50% or more, I feel I'm justified in this change.
 Others in -audit also felt it was "the right thing to do".
 
 If you still feel ANSIify this is the wrong thing to do in this case, I'd be
 more than happy to convert the prototypes back to __P() and produce a new
 patch.
 
 Best regards,
 Mike Barcroft
 
State-Changed-From-To: open->suspended 
State-Changed-By: des 
State-Changed-When: Tue Jun 12 17:53:17 PDT 2001 
State-Changed-Why:  
I'm sponsoring Mike for commit privileges, and am suspending this PR until 
core have processed his application so he can have a shot at closing it 
himself. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28082 

From: Dima Dorfman <dima@unixfreak.org>
To: Mike Barcroft <mike@q9media.com>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/28082: [patch] src/usr.bin/whois clean-up 
Date: Tue, 12 Jun 2001 21:31:19 -0700

 Mike Barcroft <mike@q9media.com> writes:
 > On 6/11/01 11:38 PM, Dima Dorfman at dima@unixfreak.org wrote:
 > 
 > > mike@q9media.com writes:
 > >> 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()
 > > 
 > > I don't think this is a good reason to ANSIify something, especially
 > > since gcc no longer complains about that.
 > 
 > Would you not agree that prototyping main() is evil? :)
 
 I agree that prototyping main() is evil in most cases.  It makes sense
 to prototype it if main() is recursive, but a program with a recursive
 main() probably has other problems ;-).
 
 > Also, was the
 > change to gcc also applied to -stable.
 
 Not yet.  But neither have the WARNS= patches, so it isn't a problem.
 David did say that he would apply the patch to -stable as well.
 
 > Eventually this change will be MFC.
 
 If it were to be MFC'd as is, no breakage would result because -stable
 doesn't have WARNS=.
 
 > 
 > I recall David saying something about it only being applied to the current
 > verion of gcc, and future versions may not have it.  I would hate to
 > introduce something that could result in future breakage, as a result of a
 > new gcc import.
 
 I don't think this will be much of a problem.  whois(1) also wouldn't
 be the only program in this position, and a temporary remedy is
 readily available, namely NO_WERROR.  Granted this isn't ideal, but
 it's enough to fix it until we can decide what to do.
 
 Furthermore, I don't think it's appropriate to ANSIify a program
 simply for the sake of removing the warning.  I don't mean this case,
 but there are programs which are WARNS=1-ready modulo this warning.
 It'd be nice to set WARNS=1 for them without having to ANSIify.
 
 > 
 > My goal was to take a more proactive step towards current style(9)
 > conventions.  Although style(9) recommends staying with current conventions
 > unless you're changing 50% or more, I feel I'm justified in this change.
 > Others in -audit also felt it was "the right thing to do".
 > 
 > If you still feel ANSIify this is the wrong thing to do in this case, I'd be
 > more than happy to convert the prototypes back to __P() and produce a new
 > patch.
 
 Personally, I don't particularly care.  It looks like DES is sponoring
 you for a commit bit, so you can decide which you prefer (probably the
 ANSIfication).
 
 Good luck!
 
 					Dima Dorfman
 					dima@unixfreak.org
 
 
 > 
 > Best regards,
 > Mike Barcroft
 > 
State-Changed-From-To: suspended->closed 
State-Changed-By: des 
State-Changed-When: Thu Jun 21 18:52:49 PDT 2001 
State-Changed-Why:  
Committed.  This patch will not be MFCed individually, as there are other 
whois(8) changes waiting in the pipeline. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28082 
>Unformatted:
