Date: Wed, 18 Sep 1996 19:33:15 -0700 (PDT) From: Jason Thorpe <thorpej@nas.nasa.gov> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/1640: libftpio not 64-bit safe Message-ID: <199609190233.TAA07506@nostromo.nas.nasa.gov> Resent-Message-ID: <199609190240.TAA11163@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 1640
>Category: bin
>Synopsis: libftpio 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 19:40:02 PDT 1996
>Last-Modified:
>Originator: Jason Thorpe
>Organization:
Numerical Aerodynamic Simulation Project - NASA Ames
>Release: FreeBSD-current 960918, built under 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:
The `ftpio' library is not 64-bit safe. Err, what else is there
to say? :-)
>How-To-Repeat:
Try building libftpio under NetBSD/alpha. Lose.
>Fix:
Diffs below to make it compile without warnings and even work! :-)
I made these changes some time ago, and just recently imported
the most recent ftpio into my private tree. Once I update the
other utilities that use ftpio, diffs for those programs will
follow.
Note the prototype of an external interface changed; ftpGetSize()
now returns an off_t rather than a size_t, since that's what
file offsets actually are.
Oh, ftpGet() changed, too ... the `seekto' argument should
be an off_t, not an int.
(You can safely ignore the $NetBSD$ tags :-)
----- snip -----
Index: ftpio.c
===================================================================
RCS file: /mastersrc/netbsd/src/lib/libftpio/ftpio.c,v
retrieving revision 1.1.1.2
retrieving revision 1.5
diff -c -r1.1.1.2 -r1.5
*** ftpio.c 1996/09/19 02:07:23 1.1.1.2
--- ftpio.c 1996/09/19 02:18:51 1.5
***************
*** 1,3 ****
--- 1,5 ----
+ /* $NetBSD: $ */
+
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
***************
*** 18,39 ****
*
*/
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <netdb.h>
- #include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
! #include <stdarg.h>
! #include <string.h>
! #include <ctype.h>
! #include <sys/signal.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
#include <arpa/inet.h>
#include <ftpio.h>
#define SUCCESS 0
#define FAILURE -1
--- 20,42 ----
*
*/
#include <sys/types.h>
#include <sys/socket.h>
+
#include <netinet/in.h>
!
#include <arpa/inet.h>
+
+ #include <ctype.h>
+ #include <errno.h>
#include <ftpio.h>
+ #include <netdb.h>
+ #include <signal.h>
+ #include <stdarg.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
#define SUCCESS 0
#define FAILURE -1
***************
*** 58,64 ****
static int botch(char *func, char *botch_state);
static int cmd(FTP_t ftp, const char *fmt, ...);
static int ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port, int verbose);
! static int ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *seekto);
static int ftp_close(FTP_t ftp);
static int get_url_info(char *url_in, char *host_ret, int *port_ret, char *name_ret);
--- 61,67 ----
static int botch(char *func, char *botch_state);
static int cmd(FTP_t ftp, const char *fmt, ...);
static int ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port, int verbose);
! static int ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, off_t *seekto);
static int ftp_close(FTP_t ftp);
static int get_url_info(char *url_in, char *host_ret, int *port_ret, char *name_ret);
***************
*** 176,187 ****
return("Unknown error");
}
! size_t
ftpGetSize(FILE *fp, char *name)
{
int i;
! char p[BUFSIZ], *cp;
FTP_t ftp = fcookie(fp);
check_passive(fp);
sprintf(p, "SIZE %s\r\n", name);
--- 179,191 ----
return("Unknown error");
}
! off_t
ftpGetSize(FILE *fp, char *name)
{
int i;
! char p[BUFSIZ], *cp, *ep;
FTP_t ftp = fcookie(fp);
+ off_t size;
check_passive(fp);
sprintf(p, "SIZE %s\r\n", name);
***************
*** 189,199 ****
fprintf(stderr, "Sending %s", p);
i = writes(ftp->fd_ctrl, p);
if (i)
! return (size_t)-1;
i = get_a_number(ftp, &cp);
if (check_code(ftp, i, 213))
! return (size_t)-1;
! return (size_t)atoi(cp);
}
time_t
--- 193,208 ----
fprintf(stderr, "Sending %s", p);
i = writes(ftp->fd_ctrl, p);
if (i)
! return (off_t)-1;
i = get_a_number(ftp, &cp);
if (check_code(ftp, i, 213))
! return (off_t)-1;
!
! errno = 0; /* to check for ERANGE */
! size = (off_t)strtoq(cp, &ep, 10);
! if (*ep != '\0' || errno == ERANGE)
! return (off_t)-1;
! return size;
}
time_t
***************
*** 230,236 ****
}
FILE *
! ftpGet(FILE *fp, char *file, int *seekto)
{
FILE *fp2;
FTP_t ftp = fcookie(fp);
--- 239,245 ----
}
FILE *
! ftpGet(FILE *fp, char *file, off_t *seekto)
{
FILE *fp2;
FTP_t ftp = fcookie(fp);
***************
*** 646,652 ****
}
static int
! ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *seekto)
{
int i,s;
char *q;
--- 655,661 ----
}
static int
! ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, off_t *seekto)
{
int i,s;
char *q;
***************
*** 700,706 ****
if (i < 0 || FTP_TIMEOUT(i)) {
close(s);
ftp->errno = i;
! *seekto = 0;
return i;
}
}
--- 709,715 ----
if (i < 0 || FTP_TIMEOUT(i)) {
close(s);
ftp->errno = i;
! *seekto = (off_t)0;
return i;
}
}
***************
*** 748,754 ****
return i;
}
else if (i != 350)
! *seekto = 0;
}
i = cmd(ftp, "%s %s", operation, file);
if (i < 0 || i > 299) {
--- 757,763 ----
return i;
}
else if (i != 350)
! *seekto = (off_t)0;
}
i = cmd(ftp, "%s %s", operation, file);
if (i < 0 || i > 299) {
Index: ftpio.h
===================================================================
RCS file: /mastersrc/netbsd/src/lib/libftpio/ftpio.h,v
retrieving revision 1.1.1.2
retrieving revision 1.4
diff -c -r1.1.1.2 -r1.4
*** ftpio.h 1996/09/19 02:07:22 1.1.1.2
--- ftpio.h 1996/09/19 02:13:27 1.4
***************
*** 1,7 ****
--- 1,10 ----
+ /* $NetBSD: $ */
+
#ifndef _FTP_H_INCLUDE
#define _FTP_H_INCLUDE
#include <sys/types.h>
+ #include <stdio.h>
#include <time.h>
/*
***************
*** 48,55 ****
extern FILE *ftpLogin(char *host, char *user, char *passwd, int port, int verbose);
extern int ftpChdir(FILE *fp, char *dir);
extern int ftpErrno(FILE *fp);
! extern size_t ftpGetSize(FILE *fp, char *file);
! extern FILE *ftpGet(FILE *fp, char *file, int *seekto);
extern FILE *ftpPut(FILE *fp, char *file);
extern int ftpAscii(FILE *fp);
extern int ftpBinary(FILE *fp);
--- 51,58 ----
extern FILE *ftpLogin(char *host, char *user, char *passwd, int port, int verbose);
extern int ftpChdir(FILE *fp, char *dir);
extern int ftpErrno(FILE *fp);
! extern off_t ftpGetSize(FILE *fp, char *file);
! extern FILE *ftpGet(FILE *fp, char *file, off_t *seekto);
extern FILE *ftpPut(FILE *fp, char *file);
extern int ftpAscii(FILE *fp);
extern int ftpBinary(FILE *fp);
>Audit-Trail:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199609190233.TAA07506>
