Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Sep 1996 20:10:12 -0700 (PDT)
From:      Jason Thorpe <thorpej@nas.nasa.gov>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/1641: fetch(1) is not 64-bit safe
Message-ID:  <199609190310.UAA07715@nostromo.nas.nasa.gov>
Resent-Message-ID: <199609190320.UAA27299@freefall.freebsd.org>

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

>Number:         1641
>Category:       bin
>Synopsis:       fetch(1) is not 64-bit safe
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 18 20:20:04 PDT 1996
>Last-Modified:
>Originator:     Jason Thorpe
>Organization:
Numerical Aerodynamic Simulation Project - NASA Ames
>Release:        FreeBSD-current 960918, build on NetBSD/alpha
>Environment:
	
System: NetBSD nostromo 1.2A NetBSD 1.2A (NOSY) #14: Wed Sep 18 14:54:10 PDT 1996 thorpej@nostromo:/work/clean-current/src/sys/arch/alpha/compile/NOSY alpha


>Description:
	fetch(1) is not 64-bit safe.

>How-To-Repeat:
	Try to build fetch(1) under NetBSD/alpha.  Lose.

>Fix:
	Below are diffs which make fetch(1) 64-bit safe (inasmuch as
	it compiles without warnings, and seems to work properly
	under NetBSD/alpha).  Also, did some minor cleaning up of
	some stuff, but I didn't get too bonkers.

	Note that these diffs assume the previously submitted changes
	to libftpio, notably the "file offsets are off_ts" changes.

 ----- snip -----
Index: main.c
===================================================================
RCS file: /mastersrc/netbsd/src/usr.bin/fetch/main.c,v
retrieving revision 1.1.1.2
retrieving revision 1.4
diff -c -r1.1.1.2 -r1.4
*** main.c	1996/09/19 02:37:53	1.1.1.2
--- main.c	1996/09/19 03:01:46	1.4
***************
*** 1,3 ****
--- 1,5 ----
+ /*	$NetBSD: $	*/
+ 
  /*-
   * Copyright (c) 1996
   *      Jean-Marc Zucconi
***************
*** 24,48 ****
   * SUCH DAMAGE.
   */
  
! /* $Id: main.c,v 1.1.1.2 1996/09/19 02:37:53 thorpej Exp $ */
  
  #include <stdlib.h>
  #include <stdio.h>
  #include <string.h>
  #include <pwd.h>
  #include <unistd.h>
! #include <sys/types.h>
! #include <sys/socket.h>
  #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <netdb.h>
! #include <sys/time.h>
  #include <regex.h>
  #include <signal.h>
- #include <sys/stat.h>
- #include <sys/errno.h>
- #include <err.h>
  #include <stdarg.h>
  
  #include <ftpio.h>
  
--- 26,58 ----
   * SUCH DAMAGE.
   */
  
! /* FreeBSD Id: main.c,v 1.21 1996/09/10 19:49:41 jkh Exp */
  
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <sys/stat.h>
+ #include <sys/time.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <string.h>
  #include <pwd.h>
  #include <unistd.h>
! 
  #include <netinet/in.h>
+ 
  #include <arpa/inet.h>
+ 
+ #include <err.h>
+ #include <errno.h>
  #include <netdb.h>
! #include <pwd.h>
  #include <regex.h>
  #include <signal.h>
  #include <stdarg.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
  
  #include <ftpio.h>
  
***************
*** 52,58 ****
  
  char buffer[BUFFER_SIZE];
  
! char *progname;
  
  int verbose = 1;
  int ftp_verbose = 0;
--- 62,68 ----
  
  char buffer[BUFFER_SIZE];
  
! extern char *__progname;		/* from crt0.o */
  
  int verbose = 1;
  int ftp_verbose = 0;
***************
*** 76,82 ****
  void usage(void), die(int), rm(void), timeout(int), ftpget(void),
      httpget(void), fileget(void),
      display(int, int), parse(char *), output_file_name(void),
!     f_size(char *, int *, time_t *), ftperr(FILE* ftp, char *, ...),
      filter(unsigned char *, int),
      setup_http_proxy(void);
  
--- 86,92 ----
  void usage(void), die(int), rm(void), timeout(int), ftpget(void),
      httpget(void), fileget(void),
      display(int, int), parse(char *), output_file_name(void),
!     f_size(char *, off_t *, time_t *), ftperr(FILE* ftp, char *, ...),
      filter(unsigned char *, int),
      setup_http_proxy(void);
  
***************
*** 85,91 ****
  void
  usage()
  {
!     fprintf(stderr, "usage: %s [-DHINPMTVLqlmnprv] [-o outputfile] <-f file -h host [-c dir]| URL>\n", progname);
      exit(1);
  }
  
--- 95,101 ----
  void
  usage()
  {
!     fprintf(stderr, "usage: %s [-DHINPMTVLqlmnprv] [-o outputfile] <-f file -h host [-c dir]| URL>\n", __progname);
      exit(1);
  }
  
***************
*** 96,104 ****
      
      rm();
      if (!sig)
! 	fprintf (stderr, "%s: %s\n", progname, sys_errlist[e]);
      else
! 	fprintf (stderr, "%s: Interrupted by signal %d\n", progname, sig);
      exit(1);
  }
  
--- 106,114 ----
      
      rm();
      if (!sig)
! 	fprintf (stderr, "%s: %s\n", __progname, strerror(e));
      else
! 	warnx ("Interrupted by signal %d", sig);
      exit(1);
  }
  
***************
*** 132,142 ****
  main(int argc, char **argv)
  {
      int c;
!     char *s = strrchr (argv[0], '/');
!     
!     progname = s ? s+1 : argv[0];
!     
!     while ((c = getopt (argc, argv, "D:HINPMT:V:Lqc:f:h:o:plmnrv")) != EOF) {
  	switch (c) {
  	case 'D': case 'H': case 'I': case 'N': case 'L': case 'V': 
  	    break;	/* ncftp compatibility */
--- 142,149 ----
  main(int argc, char **argv)
  {
      int c;
! 
!     while ((c = getopt (argc, argv, "D:HINPMT:V:Lqc:f:h:o:plmnrv")) != -1) {
  	switch (c) {
  	case 'D': case 'H': case 'I': case 'N': case 'L': case 'V': 
  	    break;	/* ncftp compatibility */
***************
*** 228,234 ****
  void
  timeout(int sig)
  {
!     fprintf(stderr, "\n%s: Timeout\n", progname);
      rm();
      exit(1);
  }
--- 235,241 ----
  void
  timeout(int sig)
  {
!     fprintf (stderr, "\n%s: Timeout\n", __progname);
      rm();
      exit(1);
  }
***************
*** 276,282 ****
      FILE *ftp, *fp;
      char *cp, *lp;
      int status, n;
!     ssize_t size, size0, seekloc;
      char ftp_pw[200];
      time_t t;
      struct itimerval timer;
--- 283,289 ----
      FILE *ftp, *fp;
      char *cp, *lp;
      int status, n;
!     off_t size, size0, seekloc;
      char ftp_pw[200];
      time_t t;
      struct itimerval timer;
***************
*** 454,460 ****
  	s += 6;
  	p = strchr(s, '/');
  	if (!p) {
! 	    fprintf(stderr, "%s: no filename??\n", progname);
  	    usage();
  	}
  	ftp = 1;
--- 461,467 ----
  	s += 6;
  	p = strchr(s, '/');
  	if (!p) {
! 	    warnx("no filename??");
  	    usage();
  	}
  	ftp = 1;
***************
*** 465,471 ****
  	s += 7;
  	p = strchr(s, '/');
  	if (!p) {
! 	    fprintf (stderr, "%s: no filename??\n", progname);
  	    usage ();
  	}
  	*p++ = 0;
--- 472,478 ----
  	s += 7;
  	p = strchr(s, '/');
  	if (!p) {
! 	    warnx ("no filename??");
  	    usage ();
  	}
  	*p++ = 0;
***************
*** 483,489 ****
  	/* assume /host.name:/file/name */
  	p = strchr (s, ':');
  	if (!p) {
! 	    fprintf (stderr, "%s: no filename??\n", progname);
  	    usage ();
  	}
      }
--- 490,496 ----
  	/* assume /host.name:/file/name */
  	p = strchr (s, ':');
  	if (!p) {
! 	    warnx ("no filename??");
  	    usage ();
  	}
      }
***************
*** 516,522 ****
  }
  
  void
! f_size (char *name, int *size, time_t *time)
  {
      struct stat s;
      
--- 523,529 ----
  }
  
  void
! f_size (char *name, off_t *size, time_t *time)
  {
      struct stat s;
      
***************
*** 584,590 ****
  	i = select (s+1, &fdset, 0, 0, &tout); 
  	switch (i) {
  	case 0:
! 	    fprintf (stderr, "%s: Timeout\n", progname);
  	    rm ();
  	    exit (1);
  	case 1:
--- 591,597 ----
  	i = select (s+1, &fdset, 0, 0, &tout); 
  	switch (i) {
  	case 0:
! 	    warnx ("Timeout");
  	    rm ();
  	    exit (1);
  	case 1:
***************
*** 711,717 ****
      }
      sin.sin_port = htons (http_port);
      if ((s = socket (sin.sin_family, SOCK_STREAM, 0)) < 0) 
! 	err (1, 0);
      bzero ((char *)&sin2, sizeof (sin2));
      sin2.sin_family = AF_INET;
      sin2.sin_port = 0;
--- 718,724 ----
      }
      sin.sin_port = htons (http_port);
      if ((s = socket (sin.sin_family, SOCK_STREAM, 0)) < 0) 
! 	err (1, "socket");
      bzero ((char *)&sin2, sizeof (sin2));
      sin2.sin_family = AF_INET;
      sin2.sin_port = 0;
***************
*** 720,726 ****
  	err (1, "could not bind to socket.");
      
      if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
! 	err (1, "connection failed.");
      return s;
  }
  
--- 727,733 ----
  	err (1, "could not bind to socket.");
      
      if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
! 	err (1, "connection failed");
      return s;
  }
  
>Audit-Trail:
>Unformatted:



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