ports/138854: [patch] net/nettest does not work correctly on 64-bit platforms.

Mike Silbersack silby at silby.com
Tue Sep 15 18:40:09 UTC 2009


>Number:         138854
>Category:       ports
>Synopsis:       [patch] net/nettest does not work correctly on 64-bit platforms.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 15 18:40:09 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Mike Silbersack
>Release:        7.0
>Organization:
>Environment:
>Description:
Some testers where I work discovered that nettest compiles, but does not operate correctly on 64-bit platforms.  I looked into it, and discovered that it was int / long confusion due to the code predating 64-bit being commonplace.  The fixes were simple.  This modification has been tested on i386 and amd64.

>How-To-Repeat:

>Fix:
Apply the attached patch to the port.

Patch attached with submission follows:

--- nettest.c.orig	2009-09-04 10:29:17.000000000 -0500
+++ nettest.c	2009-09-04 11:21:20.000000000 -0500
@@ -45,6 +45,10 @@
 #if defined(BSD44) || defined(sun) || defined(ultrix) || defined(sgi)
 #include <netinet/in_systm.h>
 #endif
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
 #include <sys/wait.h>
 #include <sys/un.h>
 #include <netinet/tcp.h>
@@ -130,10 +134,7 @@
 
 void do_children(), do_stream(), usage(), do_dgram(), prtimes();
 
-int read();
-ssize_t recv();
-
-int (*rfunc)() = read;
+ssize_t (*rfunc)() = read;
 
 main(argc, argv)
 	int argc;
@@ -611,7 +612,6 @@
 	register int i;
 	int n;
 	struct children *childrenp;
-	char *malloc();
 	int status, child_error = 0;
 	int notready = 0, nchildren;
 	struct tms	tms1, tms2;
@@ -861,14 +861,14 @@
 {
 	register int	i, t, j, offset = 0, t2;
 	register char	*cp;
-	char		buf[128], *data, *malloc(), *orgdata;
-	long		*cnts;
-	register long	*ldp;
+	char		buf[128], *data, *orgdata;
+	int		*cnts;
+	register int	*ldp;
 	struct tms	tms1, tms2, tms3;
 	TIMETYPE	start, turnaround, end;
-	register unsigned long loval;
+	register unsigned int loval;
 #ifndef	CRAY
-	register unsigned long hival;
+	register unsigned int hival;
 #endif
 
 #ifndef	NO_ISO
@@ -917,12 +917,12 @@
 		fprintf(stderr, "cannot malloc enough data space\n");
 		exit(1);
 	}
-	cnts = (long *)malloc((chunksize+1)*sizeof(long));
+	cnts = (int *)malloc((chunksize+1)*sizeof(int));
 	if (cnts == NULL) {
 		fprintf(stderr, "cannot malloc enough stats space\n");
 		exit(1);
 	}
-	bzero(cnts, (chunksize+1)*sizeof(long));
+	bzero(cnts, (chunksize+1)*sizeof(int));
 
 	if (checkdata && !seqdata)
 		for (cp = data, i = 0; i < chunksize; )
@@ -947,7 +947,7 @@
 
 	for (i = 0; i < nchunks; i++) {
 		if (seqdata) {
-			ldp = (long *)data;
+			ldp = (int *)data;
 			for (j = 0; j < chunksize/8; j++) {
 #ifndef	CRAY
 				*ldp++ = htonl(hival);
@@ -1040,12 +1040,12 @@
 		}
 		t += data - orgdata;
 		data = orgdata;
-		ldp = (long *)data;
+		ldp = (int *)data;
 		for (j = 0; j < t/8; j++) {
 #ifndef	CRAY
 			t2 = ntohl(*ldp++) != hival;
 			if ((ntohl(*ldp++) != loval) || t2) {
-				printf("expected %8x%8x, got %8x%8x\n",
+				printf("client expected %8x%8x, got %8x%8x\n",
 					hival, loval, ntohl(*(ldp-2)),
 						ntohl(*(ldp-1)));
 				hival = ntohl(*(ldp-2));
@@ -1064,9 +1064,9 @@
 		}
 		t -= j*8;
 		if (t) {
-			*(long *)orgdata = *ldp;
+			*(int *)orgdata = *ldp;
 #ifndef	CRAY
-			*(((long *)orgdata) + 1) = *(ldp+1);
+			*(((int *)orgdata) + 1) = *(ldp+1);
 #endif
 			data = orgdata + t;
 		}
@@ -1144,7 +1144,6 @@
 {
 	register int	ret, i;
 	register char	*data;
-	char		*malloc();
 	struct tms	tms1, tms2;
 	TIMETYPE	start, end;
 	struct msghdr	outmsg;
--- nettestd.c.orig	2009-09-04 10:29:24.000000000 -0500
+++ nettestd.c	2009-09-04 11:22:11.000000000 -0500
@@ -48,6 +48,9 @@
 #include <sys/un.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #ifdef	CRAY2
 #include <sys/sysmacros.h>
 #endif
@@ -79,7 +82,7 @@
 int	mesghdr = 0;
 #define	debug(x)	if(dflag>1)fprintf x
 int verbose;
-int daemon = 0;		/* are we running in daemon mode? */
+int daemon_mode = 0;		/* are we running in daemon_mode mode? */
 
 #ifdef	TCP_WINSHIFT
 int	winshift;
@@ -107,9 +110,7 @@
 } name;
 int namesize;
 
-int read();
-ssize_t recv();
-int (*rfunc)() = read;
+ssize_t (*rfunc)() = read;
 
 main(argc, argv)
 int argc;
@@ -134,13 +135,13 @@
 
 	while ((c = getopt(argc, argv, "bdimp:s:vV")) != EOF) {
 		switch(c) {
-		case 'b':	/* run as a background daemon */
+		case 'b':	/* run as a background daemon_mode */
 			if (verbose) {
 				fprintf(stderr,
 				    "-v flag ignored when -b flag is used\n");
 				verbose = 0;
 			}
-			daemon++;
+			daemon_mode++;
 			break;
 		case 'd':	/* turn on socket level debugging */
 			++dflag;
@@ -205,7 +206,7 @@
 #endif
 
 		case 'v':	/* print out errors in sequenced data */
-			if (daemon) {
+			if (daemon_mode) {
 				fprintf(stderr,
 				    "-v flag ignored when -b flag is used\n");
 				verbose = 0;
@@ -271,7 +272,7 @@
 #  endif
 # endif
 #endif
-	if (daemon) {
+	if (daemon_mode) {
 		if (setpgrp(0, getpid()) < 0)
 			perror("setpgrp");
 		if ((c = open(_PATH_TTY, O_RDWR)) >= 0) {
@@ -474,12 +475,12 @@
 #ifndef	CRAY
 #define	VRFY() { \
 		register int j, k; \
-		register long *ldp = (long *)(data + (offset&~0x7)); \
+		register int *ldp = (int *)(data + (offset&~0x7)); \
 		register int len = t + (offset&0x7); \
 		for (j = 0; j < len/8; j++) { \
 			k = (ntohl(*ldp++) != hival); \
 			if ((ntohl(*ldp++) != loval) || k) { \
-				printf("expected %8x%8x, got %8x%8x\n", \
+				printf("server expected %8x%8x, got %8x%8x\n", \
 					hival, loval, ntohl(*(ldp-2)), \
 					ntohl(*(ldp-1))); \
 				hival = ntohl(*(ldp-2)); \
@@ -496,7 +497,7 @@
 #else
 #define	VRFY() { \
 		register int j; \
-		register long *ldp = (long *)(data + (offset&~0x7)); \
+		register int *ldp = (int *)(data + (offset&~0x7)); \
 		register int len = t + (offset&0x7); \
 		for (j = 0; j < len/8; j++) { \
 			if (*ldp++ != loval) { \
@@ -517,10 +518,10 @@
 {
 	register int	i, t, offset = 0;
 	register char	*cp, *data;
-	char		buf[128], *malloc();
+	char		buf[128];
 	int		chunks = 0, chunksize = 0, fullbuf = 0, kbufsize = 0;
 	int		tos = 0, nodelay = 0, seqdata = 0, waitall = 0;
-	register unsigned long hival, loval;
+	register unsigned int hival, loval;
 
 #ifndef NO_ISO
 	/* read ISO CR - 0 bytes of data */
@@ -636,7 +637,7 @@
 	for (i = 0; i < chunks; i++) {
 		if (seqdata) {
 			register int j;
-			register long *ldp = (long *)data;
+			register int *ldp = (int *)data;
 			for (j = 0; j < chunksize/8; j++) {
 #ifndef	CRAY
 				*ldp++ = htonl(hival);
@@ -685,7 +686,7 @@
 	register int		t, t2;
 	register char		*cp, *data;
 	register struct hostent	*hp;
-	char			*inet_ntoa(), *malloc();
+	char			*inet_ntoa();
 	register char		*errmsg;
 #ifdef	CMSG_DATA
 	struct msghdr		inmsg;
@@ -759,7 +760,7 @@
 error(string)
 char *string;
 {
-	if (daemon)
+	if (daemon_mode)
 		syslog(LOG_ERR, "nettestd: %s %m", string);
 	else
 		perror(string);


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



More information about the freebsd-ports-bugs mailing list