summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ftp/Makefile6
-rw-r--r--usr.bin/ftp/cmds.c42
-rw-r--r--usr.bin/ftp/cmdtab.c6
-rw-r--r--usr.bin/ftp/complete.c60
-rw-r--r--usr.bin/ftp/domacro.c8
-rw-r--r--usr.bin/ftp/extern.h9
-rw-r--r--usr.bin/ftp/fetch.c135
-rw-r--r--usr.bin/ftp/ftp.16
-rw-r--r--usr.bin/ftp/ftp.c70
-rw-r--r--usr.bin/ftp/ftp_var.h14
-rw-r--r--usr.bin/ftp/main.c28
-rw-r--r--usr.bin/ftp/ruserpass.c12
-rw-r--r--usr.bin/ftp/stringlist.c10
-rw-r--r--usr.bin/ftp/util.c66
14 files changed, 287 insertions, 185 deletions
diff --git a/usr.bin/ftp/Makefile b/usr.bin/ftp/Makefile
index a0a852cf725..735185cc29f 100644
--- a/usr.bin/ftp/Makefile
+++ b/usr.bin/ftp/Makefile
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile,v 1.9 1997/04/10 00:17:06 millert Exp $
-# $NetBSD: Makefile,v 1.11 1997/03/24 21:59:36 christos Exp $
+# $OpenBSD: Makefile,v 1.10 1997/07/25 21:56:16 millert Exp $
+# $NetBSD: Makefile,v 1.12 1997/07/20 09:45:35 lukem Exp $
# from: @(#)Makefile 8.2 (Berkeley) 4/3/94
# define SMALL to disable command line editing
@@ -12,4 +12,6 @@ SRCS= cmds.c cmdtab.c complete.c domacro.c fetch.c ftp.c main.c ruserpass.c \
LDADD+= -ledit -ltermcap
DPADD+= ${LIBEDIT} ${LIBTERMCAP}
+#COPTS+= -Wall -Wconversion -Wstrict-prototypes -Wmissing-prototypes
+
.include <bsd.prog.mk>
diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c
index cadf58742f6..a1c2330e309 100644
--- a/usr.bin/ftp/cmds.c
+++ b/usr.bin/ftp/cmds.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: cmds.c,v 1.20 1997/04/23 20:32:57 deraadt Exp $ */
-/* $NetBSD: cmds.c,v 1.23 1997/04/14 09:09:15 lukem Exp $ */
+/* $OpenBSD: cmds.c,v 1.21 1997/07/25 21:56:17 millert Exp $ */
+/* $NetBSD: cmds.c,v 1.26 1997/07/21 14:03:48 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: cmds.c,v 1.20 1997/04/23 20:32:57 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: cmds.c,v 1.21 1997/07/25 21:56:17 millert Exp $";
#endif
#endif /* not lint */
@@ -340,7 +340,7 @@ mput(argc, argv)
if (!*tp) {
tp = cp;
tp2 = tmpbuf;
- while ((*tp2 = *tp) != NULL) {
+ while ((*tp2 = *tp) != '\0') {
if (isupper(*tp2)) {
*tp2 = 'a' + *tp2 - 'A';
}
@@ -483,7 +483,7 @@ usage:
if (!*tp) {
tp = argv[2];
tp2 = tmpbuf;
- while ((*tp2 = *tp) != NULL) {
+ while ((*tp2 = *tp) != '\0') {
if (isupper(*tp2)) {
*tp2 = 'a' + *tp2 - 'A';
}
@@ -583,17 +583,15 @@ mget(argc, argv)
if (mflag && confirm(argv[0], cp)) {
tp = cp;
if (mcase) {
- for (tp2 = tmpbuf; (ch = *tp++) != NULL; )
+ for (tp2 = tmpbuf; (ch = *tp++) != 0; )
*tp2++ = isupper(ch) ? tolower(ch) : ch;
*tp2 = '\0';
tp = tmpbuf;
}
- if (ntflag) {
+ if (ntflag)
tp = dotrans(tp);
- }
- if (mapflag) {
+ if (mapflag)
tp = domap(tp);
- }
recvrequest("RETR", tp, cp, "w",
tp != cp || !interactive);
if (!mflag && fromatty) {
@@ -875,8 +873,6 @@ setdebug(argc, argv)
int argc;
char *argv[];
{
- int val;
-
if (argc > 2) {
fprintf(ttyout, "usage: %s [ on | off | debuglevel ]\n", argv[0]);
code = -1;
@@ -887,13 +883,17 @@ setdebug(argc, argv)
else if (strcasecmp(argv[1], "off") == 0)
debug = 0;
else {
- val = atoi(argv[1]);
- if (val < 0) {
- fprintf(ttyout, "%s: bad debugging value.\n", argv[1]);
+ char *ep;
+ long val;
+
+ val = strtol(argv[1], &ep, 10);
+ if (val < 0 || val > INT_MAX || *ep != '\0') {
+ fprintf(ttyout, "%s: bad debugging value.\n",
+ argv[1]);
code = -1;
return;
}
- debug = val;
+ debug = (int)val;
}
} else
debug = !debug;
@@ -1094,7 +1094,7 @@ mls(argc, argv)
{
sig_t oldintr;
int ointer, i;
- const char *cmd;
+ int dolist;
char mode[1], *dest;
if (argc < 2 && !another(&argc, &argv, "remote-files"))
@@ -1113,14 +1113,14 @@ usage:
code = -1;
return;
}
- cmd = strcmp(argv[0], "mls") == 0 ? "NLST" : "LIST";
+ dolist = strcmp(argv[0], "mls");
mname = argv[0];
mflag = 1;
oldintr = signal(SIGINT, mabort);
(void)setjmp(jabort);
for (i = 1; mflag && i < argc-1; ++i) {
*mode = (i == 1) ? 'w' : 'a';
- recvrequest(cmd, dest, argv[i], mode, 0);
+ recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode, 0);
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
@@ -1168,7 +1168,7 @@ shell(argc, argv)
shellnam[0] = '+';
if (debug) {
fputs(shell, ttyout);
- fputs("\n", ttyout);
+ fputc('\n', ttyout);
(void)fflush(ttyout);
}
if (argc > 1) {
@@ -1923,7 +1923,7 @@ restart(argc, argv)
else {
restart_point = atol(argv[1]);
fprintf(ttyout, "Restarting at %qd. Execute get, put or append to"
- "initiate transfer\n", restart_point);
+ "initiate transfer\n", (quad_t)restart_point);
}
}
diff --git a/usr.bin/ftp/cmdtab.c b/usr.bin/ftp/cmdtab.c
index a15453a130a..35963381815 100644
--- a/usr.bin/ftp/cmdtab.c
+++ b/usr.bin/ftp/cmdtab.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: cmdtab.c,v 1.9 1997/04/10 00:17:08 millert Exp $ */
-/* $NetBSD: cmdtab.c,v 1.15 1997/04/05 03:27:33 lukem Exp $ */
+/* $OpenBSD: cmdtab.c,v 1.10 1997/07/25 21:56:18 millert Exp $ */
+/* $NetBSD: cmdtab.c,v 1.16 1997/07/20 09:45:41 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.9 1997/04/10 00:17:08 millert Exp $";
+static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.10 1997/07/25 21:56:18 millert Exp $";
#endif
#endif /* not lint */
diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c
index 83996b12473..efda6057106 100644
--- a/usr.bin/ftp/complete.c
+++ b/usr.bin/ftp/complete.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: complete.c,v 1.7 1997/04/23 20:33:00 deraadt Exp $ */
-/* $NetBSD: complete.c,v 1.7 1997/04/14 09:09:16 lukem Exp $ */
+/* $OpenBSD: complete.c,v 1.8 1997/07/25 21:56:18 millert Exp $ */
+/* $NetBSD: complete.c,v 1.9 1997/07/20 09:45:43 lukem Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
#ifndef SMALL
#ifndef lint
-static char rcsid[] = "$OpenBSD: complete.c,v 1.7 1997/04/23 20:33:00 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: complete.c,v 1.8 1997/07/25 21:56:18 millert Exp $";
#endif /* not lint */
/*
@@ -55,6 +55,12 @@ static char rcsid[] = "$OpenBSD: complete.c,v 1.7 1997/04/23 20:33:00 deraadt Ex
#include "ftp_var.h"
+static int comparstr __P((const void *, const void *));
+static unsigned char complete_ambiguous __P((char *, int, StringList *));
+static unsigned char complete_command __P((char *, int));
+static unsigned char complete_local __P((char *, int));
+static unsigned char complete_remote __P((char *, int));
+
static int
comparstr(a, b)
const void *a, *b;
@@ -80,7 +86,8 @@ complete_ambiguous(word, list, words)
{
char insertstr[MAXPATHLEN];
char *lastmatch;
- int i, j, matchlen, wordlen;
+ int i, j;
+ size_t matchlen, wordlen;
wordlen = strlen(word);
if (words->sl_cur == 0)
@@ -134,7 +141,7 @@ complete_command(word, list)
{
struct cmd *c;
StringList *words;
- int wordlen;
+ size_t wordlen;
unsigned char rv;
words = sl_init();
@@ -176,7 +183,7 @@ complete_local(word, list)
dir[0] = '/';
dir[1] = '\0';
} else {
- (void)strncpy(dir, word, file - word);
+ (void)strncpy(dir, word, (size_t)(file - word));
dir[file - word] = '\0';
}
file++;
@@ -234,28 +241,14 @@ complete_remote(word, list)
cp = file;
while (*cp == '/' && cp > word)
cp--;
- if (cp == word) {
- dir[0] = '/';
- dir[1] = '\0';
- } else {
- (void)strncpy(dir, word, cp - word + 1);
- dir[cp - word + 1] = '\0';
- }
+ (void)strncpy(dir, word, (size_t)(cp - word + 1));
+ dir[cp - word + 1] = '\0';
file++;
}
if (dirchange || strcmp(dir, lastdir) != 0) { /* dir not cached */
char *emesg;
- int dirlen, ftpdslashbug;
-
- dirlen = strlen(dir);
- ftpdslashbug = 0;
- if (strcmp(dir, "/") == 0)
- ftpdslashbug = 1;
- else if (strcmp(dir, ".") == 0)
- dirlen = 0;
- else
- dirlen++;
+
if (dirlist != NULL)
sl_free(dirlist, 1);
dirlist = sl_init();
@@ -271,15 +264,12 @@ complete_remote(word, list)
mflag = 0;
continue;
}
- /*
- * Work around ftpd(1) bug, which puts a // instead
- * of / in front of each filename returned by "NLST /".
- * Without this, remote completes of / don't work.
- * However, only do this if the bug is present.
- */
- if (ftpdslashbug && (cp[dirlen] != '/'))
- ftpdslashbug = 0;
- tcp = strdup(cp + dirlen + ftpdslashbug);
+ tcp = strrchr(cp, '/');
+ if (tcp)
+ tcp++;
+ else
+ tcp = cp;
+ tcp = strdup(tcp);
if (tcp == NULL)
errx(1, "Can't allocate memory for remote dir");
sl_add(dirlist, tcp);
@@ -318,7 +308,8 @@ complete(el, ch)
struct cmd *c;
const LineInfo *lf;
- int len, celems, dolist;
+ int celems, dolist;
+ size_t len;
lf = el_line(el);
len = lf->lastchar - lf->buffer;
@@ -380,4 +371,5 @@ complete(el, ch)
return (CC_ERROR);
}
-#endif
+
+#endif /* !SMALL */
diff --git a/usr.bin/ftp/domacro.c b/usr.bin/ftp/domacro.c
index b00d82c4489..e48146e8634 100644
--- a/usr.bin/ftp/domacro.c
+++ b/usr.bin/ftp/domacro.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: domacro.c,v 1.6 1997/04/23 20:33:02 deraadt Exp $ */
-/* $NetBSD: domacro.c,v 1.9 1997/03/13 06:23:14 lukem Exp $ */
+/* $OpenBSD: domacro.c,v 1.7 1997/07/25 21:56:19 millert Exp $ */
+/* $NetBSD: domacro.c,v 1.10 1997/07/20 09:45:45 lukem Exp $ */
/*
* Copyright (c) 1985, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)domacro.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: domacro.c,v 1.6 1997/04/23 20:33:02 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: domacro.c,v 1.7 1997/07/25 21:56:19 millert Exp $";
#endif
#endif /* not lint */
@@ -135,7 +135,7 @@ TOP:
else {
if (verbose) {
fputs(line, ttyout);
- fputs("\n", ttyout);
+ fputc('\n', ttyout);
}
(*c->c_handler)(margc, margv);
if (bell && c->c_bell) {
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h
index 7b6cac81058..2abb286eb39 100644
--- a/usr.bin/ftp/extern.h
+++ b/usr.bin/ftp/extern.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: extern.h,v 1.14 1997/06/10 19:39:53 millert Exp $ */
-/* $NetBSD: extern.h,v 1.15 1997/04/14 09:09:17 lukem Exp $ */
+/* $OpenBSD: extern.h,v 1.15 1997/07/25 21:56:19 millert Exp $ */
+/* $NetBSD: extern.h,v 1.16 1997/07/20 09:45:48 lukem Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@@ -42,7 +42,6 @@ void abort_remote __P((FILE *));
void abortpt __P((int));
void abortrecv __P((int));
void abortsend __P((int));
-void aborthttp __P((int));
void account __P((int, char **));
void alarmtimer __P((int));
int another __P((int *, char ***, const char *));
@@ -69,7 +68,7 @@ char *domap __P((char *));
void doproxy __P((int, char **));
char *dotrans __P((char *));
int empty __P((struct fd_set *, int));
-int foregroundproc __P(());
+int foregroundproc __P((void));
void get __P((int, char **));
struct cmd *getcmd __P((const char *));
int getit __P((int, char **, int, const char *));
@@ -77,7 +76,7 @@ int getreply __P((int));
int globulize __P((char **));
char *gunique __P((const char *));
void help __P((int, char **));
-char *hookup __P((const char *, int));
+char *hookup __P((const char *, in_port_t));
void idle __P((int, char **));
int initconn __P((void));
void intr __P((void));
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index a02399eedab..bc46dbb30f9 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: fetch.c,v 1.13 1997/07/24 14:22:21 deraadt Exp $ */
-/* $NetBSD: fetch.c,v 1.8 1997/04/21 18:45:47 lukem Exp $ */
+/* $OpenBSD: fetch.c,v 1.14 1997/07/25 21:56:20 millert Exp $ */
+/* $NetBSD: fetch.c,v 1.13 1997/07/20 12:49:26 lukem Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: fetch.c,v 1.13 1997/07/24 14:22:21 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: fetch.c,v 1.14 1997/07/25 21:56:20 millert Exp $";
#endif /* not lint */
/*
@@ -66,6 +66,10 @@ static char rcsid[] = "$OpenBSD: fetch.c,v 1.13 1997/07/24 14:22:21 deraadt Exp
#include "ftp_var.h"
+static int url_get __P((const char *, const char *, int));
+void aborthttp __P((int));
+
+
#define FTP_URL "ftp://" /* ftp URL prefix */
#define HTTP_URL "http://" /* http URL prefix */
#define FTP_PROXY "ftp_proxy" /* env var with ftp proxy location */
@@ -81,59 +85,87 @@ jmp_buf httpabort;
* Modifies the string argument given.
* Returns -1 on failure, 0 on success
*/
-int
-url_get(line, proxyenv, fd)
- char *line;
- char *proxyenv;
+static int
+url_get(origline, proxyenv, fd)
+ const char *origline;
+ const char *proxyenv;
int fd;
{
struct sockaddr_in sin;
- int i, out, port, s;
- size_t buflen, len;
- char c, *cp, *cp2, *savefile, *portnum, *path, buf[4096];
- char *proxy, *host;
- sig_t oldintr;
+ int i, out, isftpurl;
+ in_port_t port;
+ volatile int s;
+ size_t len;
+ char c, *cp, *ep, *portnum, *path, buf[4096];
+ const char *savefile;
+ char *line, *proxy, *host;
+ volatile sig_t oldintr;
off_t hashbytes;
s = -1;
proxy = NULL;
+ isftpurl = 0;
+
+#ifdef __GNUC__ /* XXX: to shut up gcc warnings */
+ (void)&out;
+ (void)&proxy;
+ (void)&savefile;
+#endif
+ line = strdup(origline);
+ if (line == NULL)
+ errx(1, "Can't allocate memory to parse URL");
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0)
host = line + sizeof(HTTP_URL) - 1;
- else if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0)
+ else if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
host = line + sizeof(FTP_URL) - 1;
- else
- errx(1, "url_get: invalid url '%s'", line);
+ isftpurl = 1;
+ } else
+ errx(1, "url_get: Invalid URL '%s'", line);
path = strchr(host, '/'); /* find path */
- if (EMPTYSTRING(path))
+ if (EMPTYSTRING(path)) {
+ if (isftpurl)
+ goto noftpautologin;
+ warnx("Invalid URL (no `/' after host): %s", origline);
goto cleanup_url_get;
+ }
*path++ = '\0';
- if (EMPTYSTRING(path))
+ if (EMPTYSTRING(path)) {
+ if (isftpurl)
+ goto noftpautologin;
+ warnx("Invalid URL (no file after host): %s", origline);
goto cleanup_url_get;
+ }
savefile = strrchr(path, '/'); /* find savefile */
if (savefile != NULL)
savefile++;
else
savefile = path;
- if (EMPTYSTRING(savefile))
+ if (EMPTYSTRING(savefile)) {
+ if (isftpurl)
+ goto noftpautologin;
+ warnx("Invalid URL (no file after directory): %s", origline);
goto cleanup_url_get;
+ }
if (proxyenv != NULL) { /* use proxy */
proxy = strdup(proxyenv);
if (proxy == NULL)
- errx(1, "Can't allocate memory for proxy url.");
+ errx(1, "Can't allocate memory for proxy URL.");
if (strncasecmp(proxy, HTTP_URL, sizeof(HTTP_URL) - 1) == 0)
host = proxy + sizeof(HTTP_URL) - 1;
else if (strncasecmp(proxy, FTP_URL, sizeof(FTP_URL) - 1) == 0)
host = proxy + sizeof(FTP_URL) - 1;
else {
- warnx("Malformed proxy URL: %s", proxy);
+ warnx("Malformed proxy URL: %s", proxyenv);
goto cleanup_url_get;
}
- if (EMPTYSTRING(host))
+ if (EMPTYSTRING(host)) {
+ warnx("Malformed proxy URL: %s", proxyenv);
goto cleanup_url_get;
+ }
*--path = '/'; /* add / back to real path */
path = strchr(host, '/'); /* remove trailing / on host */
if (! EMPTYSTRING(path))
@@ -169,23 +201,26 @@ url_get(line, proxyenv, fd)
warnx("%s: not an Internet address?", host);
goto cleanup_url_get;
}
- memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
+ memcpy(&sin.sin_addr, hp->h_addr, (size_t)hp->h_length);
}
if (! EMPTYSTRING(portnum)) {
- port = atoi(portnum);
- if (port < 1 || (port & 0xffff) != port) {
+ char *ep;
+ long nport;
+
+ nport = strtol(portnum, &ep, 10);
+ if (nport < 1 || nport > 0xffff || *ep != '\0') {
warnx("Invalid port: %s", portnum);
goto cleanup_url_get;
}
- port = htons(port);
+ port = htons((in_port_t)nport);
} else
port = httpport;
sin.sin_port = port;
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1) {
- warnx("Can't create socket");
+ warn("Can't create socket");
goto cleanup_url_get;
}
@@ -199,27 +234,27 @@ url_get(line, proxyenv, fd)
* status of "200". Proxy requests don't want leading /.
*/
if (!proxy)
- fprintf(ttyout, "Requesting %s:%d/%s\n", line, ntohs(port),
- path);
+ fprintf(ttyout, "Requesting %s\n", origline);
else
- fprintf(ttyout, "Requesting %s (via %s)\n", line, proxyenv);
+ fprintf(ttyout, "Requesting %s (via %s)\n", origline, proxyenv);
snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n",
proxy ? "" : "/", path);
- buflen = strlen(buf);
- if (write(s, buf, buflen) < buflen) {
- warn("write");
+ len = strlen(buf);
+ if (write(s, buf, len) < len) {
+ warn("Writing HTTP request");
goto cleanup_url_get;
}
memset(buf, 0, sizeof(buf));
- for (i = 0, buflen = sizeof(buf), cp = buf; i < buflen; cp++, i++) {
+ for (cp = buf; cp < buf + sizeof(buf); ) {
if (read(s, cp, 1) != 1)
goto improper;
if (*cp == '\r')
continue;
if (*cp == '\n')
break;
+ cp++;
}
- buf[buflen - 1] = '\0'; /* sanity */
+ buf[sizeof(buf) - 1] = '\0'; /* sanity */
cp = strchr(buf, ' ');
if (cp == NULL)
goto improper;
@@ -235,7 +270,7 @@ url_get(line, proxyenv, fd)
*/
memset(buf, 0, sizeof(buf));
c = '\0';
- for (i = 0, buflen = sizeof(buf), cp = buf; i < buflen; cp++, i++) {
+ for (cp = buf; cp < buf + sizeof(buf); ) {
if (read(s, cp, 1) != 1)
goto improper;
if (*cp == '\r')
@@ -243,8 +278,9 @@ url_get(line, proxyenv, fd)
if (*cp == '\n' && c == '\n')
break;
c = *cp;
+ cp++;
}
- buf[buflen - 1] = '\0'; /* sanity */
+ buf[sizeof(buf) - 1] = '\0'; /* sanity */
/* Look for the "Content-length: " header. */
#define CONTENTLEN "Content-Length: "
@@ -255,13 +291,13 @@ url_get(line, proxyenv, fd)
}
if (*cp != '\0') {
cp += sizeof(CONTENTLEN) - 1;
- cp2 = strchr(cp, '\n');
- if (cp2 == NULL)
+ ep = strchr(cp, '\n');
+ if (ep == NULL)
goto improper;
else
- *cp2 = '\0';
- filesize = atoi(cp);
- if (filesize < 1)
+ *ep = '\0';
+ filesize = strtol(cp, &ep, 10);
+ if (filesize < 1 || *ep != '\0')
goto improper;
} else
filesize = -1;
@@ -329,15 +365,23 @@ url_get(line, proxyenv, fd)
close(out);
if (proxy)
free(proxy);
+ free(line);
return (0);
+noftpautologin:
+ warnx(
+ "Auto-login using ftp URLs isn't supported when using $ftp_proxy");
+ goto cleanup_url_get;
+
improper:
warnx("Improper response from %s", host);
+
cleanup_url_get:
if (s != -1)
close(s);
if (proxy)
free(proxy);
+ free(line);
return (-1);
}
@@ -380,9 +424,10 @@ auto_fetch(argc, argv, fd)
char *cp, *line, *host, *dir, *file, *portnum;
char *user, *pass;
char *ftpproxy, *httpproxy;
- int rval, xargc, argpos;
+ int rval, xargc;
+ volatile int argpos;
int dirhasglob, filehasglob;
- char rempath[MAXPATHLEN], fakedev[MAXPATHLEN];
+ char rempath[MAXPATHLEN];
argpos = 0;
@@ -444,7 +489,7 @@ auto_fetch(argc, argv, fd)
}
if (pass == host || *pass == '@') {
bad_ftp_url:
- warnx("Bad ftp URL: %s", argv[argpos]);
+ warnx("Invalid URL: %s", argv[argpos]);
rval = argpos + 1;
continue;
}
@@ -524,7 +569,7 @@ parsed_url:
setpeer(xargc, xargv);
autologin = oautologin;
if ((connected == 0) ||
- ((connected == 1) && !login(host, user, pass)) ) {
+ ((connected == 1) && !login(host, user, pass))) {
warnx("Can't connect or login to host `%s'",
host);
rval = argpos + 1;
diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1
index 0c1cb0d53fb..0f08e9d8b09 100644
--- a/usr.bin/ftp/ftp.1
+++ b/usr.bin/ftp/ftp.1
@@ -1,5 +1,5 @@
-.\" $OpenBSD: ftp.1,v 1.12 1997/04/23 20:33:09 deraadt Exp $
-.\" $NetBSD: ftp.1,v 1.20 1997/04/14 09:09:20 lukem Exp $
+.\" $OpenBSD: ftp.1,v 1.13 1997/07/25 21:56:20 millert Exp $
+.\" $NetBSD: ftp.1,v 1.21 1997/06/10 21:59:58 lukem Exp $
.\"
.\" Copyright (c) 1985, 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -1054,7 +1054,7 @@ If
.Ic file
contains a glob character and globbing is enabled,
(see
-.Ic glob ),
+.Ic glob ) ,
then the equivalent of
.Ic "mget file"
is performed.
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index 03fe620ae39..3057d1095de 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: ftp.c,v 1.19 1997/06/17 20:40:40 kstailey Exp $ */
-/* $NetBSD: ftp.c,v 1.25 1997/04/14 09:09:22 lukem Exp $ */
+/* $OpenBSD: ftp.c,v 1.20 1997/07/25 21:56:21 millert Exp $ */
+/* $NetBSD: ftp.c,v 1.26 1997/07/20 09:45:53 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-static char rcsid[] = "$OpenBSD: ftp.c,v 1.19 1997/06/17 20:40:40 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: ftp.c,v 1.20 1997/07/25 21:56:21 millert Exp $";
#endif
#endif /* not lint */
@@ -86,9 +86,9 @@ FILE *cin, *cout;
char *
hookup(host, port)
const char *host;
- int port;
+ in_port_t port;
{
- struct hostent *hp = 0;
+ struct hostent *hp = NULL;
int s, len, tos;
static char hostnamebuf[MAXHOSTNAMELEN];
@@ -105,7 +105,8 @@ hookup(host, port)
return ((char *) 0);
}
hisctladdr.sin_family = hp->h_addrtype;
- memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0], hp->h_length);
+ memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
+ (size_t)hp->h_length);
(void)strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf) - 1);
hostnamebuf[sizeof(hostnamebuf) - 1] = '\0';
}
@@ -128,7 +129,7 @@ hookup(host, port)
warn("connect to address %s", ia);
hp->h_addr_list++;
memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
- hp->h_length);
+ (size_t)hp->h_length);
fprintf(ttyout, "Trying %s...\n", inet_ntoa(hisctladdr.sin_addr));
(void)close(s);
s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
@@ -415,15 +416,26 @@ sendrequest(cmd, local, remote, printnames)
{
struct stat st;
int c, d;
- FILE *fin, *dout = 0;
+ FILE *fin, *dout;
int (*closefunc) __P((FILE *));
sig_t oldinti, oldintr, oldintp;
- off_t hashbytes;
+ volatile off_t hashbytes;
char *lmode, buf[BUFSIZ], *bufp;
int oprogress;
+#ifdef __GNUC__ /* XXX: to shut up gcc warnings */
+ (void)&fin;
+ (void)&dout;
+ (void)&closefunc;
+ (void)&oldinti;
+ (void)&oldintr;
+ (void)&oldintp;
+ (void)&lmode;
+#endif
+
hashbytes = mark;
direction = "sent";
+ dout = NULL;
bytes = 0;
filesize = -1;
oprogress = progress;
@@ -583,7 +595,8 @@ sendrequest(cmd, local, remote, printnames)
while ((c = read(fileno(fin), buf, sizeof(buf))) > 0) {
bytes += c;
for (bufp = buf; c > 0; c -= d, bufp += d)
- if ((d = write(fileno(dout), bufp, c)) <= 0)
+ if ((d = write(fileno(dout), bufp, (size_t)c))
+ <= 0)
break;
if (hash && (!progress || filesize < 0) ) {
while (bytes >= hashbytes) {
@@ -703,21 +716,36 @@ recvrequest(cmd, local, remote, lmode, printnames)
const char *cmd, *local, *remote, *lmode;
int printnames;
{
- FILE *fout, *din = 0;
+ FILE *fout, *din;
int (*closefunc) __P((FILE *));
sig_t oldinti, oldintr, oldintp;
- int c, d, is_retr, tcrflag, bare_lfs = 0;
- static int bufsize;
+ int c, d;
+ volatile int is_retr, tcrflag, bare_lfs;
+ static size_t bufsize;
static char *buf;
- off_t hashbytes;
+ volatile off_t hashbytes;
struct stat st;
time_t mtime;
int oprogress;
int opreserve;
+#ifdef __GNUC__ /* XXX: to shut up gcc warnings */
+ (void)&local;
+ (void)&fout;
+ (void)&din;
+ (void)&closefunc;
+ (void)&oldinti;
+ (void)&oldintr;
+ (void)&oldintp;
+#endif
+
+ fout = NULL;
+ din = NULL;
+ oldinti = NULL;
hashbytes = mark;
direction = "received";
bytes = 0;
+ bare_lfs = 0;
filesize = -1;
oprogress = progress;
opreserve = preserve;
@@ -779,7 +807,7 @@ recvrequest(cmd, local, remote, lmode, printnames)
return;
}
if (!runique && errno == EACCES &&
- chmod(local, 0600) < 0) {
+ chmod(local, (S_IRUSR|S_IWUSR)) < 0) {
warn("local: %s", local);
(void)signal(SIGINT, oldintr);
(void)signal(SIGINFO, oldinti);
@@ -891,7 +919,7 @@ recvrequest(cmd, local, remote, lmode, printnames)
}
errno = d = 0;
while ((c = read(fileno(din), buf, bufsize)) > 0) {
- if ((d = write(fileno(fout), buf, c)) != c)
+ if ((d = write(fileno(fout), buf, (size_t)c)) != c)
break;
bytes += c;
if (hash && (!progress || filesize < 0)) {
@@ -1343,10 +1371,18 @@ proxtrans(cmd, local, remote)
const char *cmd, *local, *remote;
{
sig_t oldintr;
- int secndflag = 0, prox_type, nfnd;
+ int prox_type, nfnd;
+ volatile int secndflag;
char *cmd2;
struct fd_set mask;
+#ifdef __GNUC__ /* XXX: to shut up gcc warnings */
+ (void)&oldintr;
+ (void)&cmd2;
+#endif
+
+ oldintr = NULL;
+ secndflag = 0;
if (strcmp(cmd, "RETR"))
cmd2 = "RETR";
else
diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h
index 747c4d5a8b6..337c18932c1 100644
--- a/usr.bin/ftp/ftp_var.h
+++ b/usr.bin/ftp/ftp_var.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: ftp_var.h,v 1.12 1997/04/23 20:33:16 deraadt Exp $ */
-/* $NetBSD: ftp_var.h,v 1.16 1997/04/14 09:09:23 lukem Exp $ */
+/* $OpenBSD: ftp_var.h,v 1.13 1997/07/25 21:56:21 millert Exp $ */
+/* $NetBSD: ftp_var.h,v 1.17 1997/07/20 09:45:55 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -106,7 +106,7 @@ char bytename[32]; /* local byte size in ascii */
int bytesize; /* local byte size in binary */
int anonftp; /* automatic anonymous login */
int dirchange; /* remote directory changed by cd command */
-int retry_connect; /* retry connect if failed */
+unsigned int retry_connect; /* retry connect if failed */
int ttywidth; /* width of tty */
#ifndef SMALL
@@ -114,8 +114,8 @@ int editing; /* command line editing enabled */
EditLine *el; /* editline(3) status structure */
History *hist; /* editline(3) history structure */
char *cursor_pos; /* cursor position we're looking for */
-int cursor_argc; /* location of cursor in margv */
-int cursor_argo; /* offset of cursor in margv[cursor_argc] */
+size_t cursor_argc; /* location of cursor in margv */
+size_t cursor_argo; /* offset of cursor in margv[cursor_argc] */
#endif /* !SMALL */
off_t bytes; /* current # of bytes read */
@@ -125,8 +125,8 @@ char *direction; /* direction transfer is occurring */
char *hostname; /* name of host connected to */
int unix_server; /* server is unix, can use binary for ascii */
int unix_proxy; /* proxy is unix, can use binary for ascii */
-int ftpport; /* port number to use for ftp connections */
-int httpport; /* port number to use for http connections */
+in_port_t ftpport; /* port number to use for ftp connections */
+in_port_t httpport; /* port number to use for http connections */
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c
index ac879c23370..93efb670a55 100644
--- a/usr.bin/ftp/main.c
+++ b/usr.bin/ftp/main.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: main.c,v 1.33 1997/06/10 19:39:54 millert Exp $ */
-/* $NetBSD: main.c,v 1.21 1997/04/05 03:27:39 lukem Exp $ */
+/* $OpenBSD: main.c,v 1.34 1997/07/25 21:56:22 millert Exp $ */
+/* $NetBSD: main.c,v 1.23 1997/07/20 09:45:58 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.33 1997/06/10 19:39:54 millert Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.34 1997/07/25 21:56:22 millert Exp $";
#endif
#endif /* not lint */
@@ -65,13 +65,16 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.33 1997/06/10 19:39:54 millert Exp $
#include "ftp_var.h"
+int main __P((int, char **));
+
int
main(argc, argv)
int argc;
char *argv[];
{
struct servent *sp;
- int ch, top, port, rval;
+ int ch, top, rval;
+ long port;
struct passwd *pw = NULL;
char *cp, homedir[MAXPATHLEN];
int dumb_terminal = 0;
@@ -115,13 +118,13 @@ main(argc, argv)
verbose = 1; /* verbose if from a tty */
#ifndef SMALL
if (!dumb_terminal)
- editing = 1; /* editing mode on if from a tty */
+ editing = 1; /* editing mode on if tty is usable */
#endif
}
ttyout = stdout;
if (isatty(fileno(ttyout)) && !dumb_terminal && foregroundproc())
- progress = 1; /* progress bar on if going to a tty */
+ progress = 1; /* progress bar on if tty is usable */
if (!isatty(fileno(ttyout))) {
outfd = fileno(stdout);
@@ -162,11 +165,11 @@ main(argc, argv)
break;
case 'P':
- port = atoi(optarg);
- if (port <= 0)
+ port = strtol(optarg, &cp, 10);
+ if (port < 1 || port > 0xffff || *cp != '\0')
warnx("bad port number: %s (ignored)", optarg);
else
- ftpport = htons(port);
+ ftpport = htons((in_port_t)port);
break;
case 'r':
@@ -216,6 +219,11 @@ main(argc, argv)
setttywidth(0);
(void)signal(SIGWINCH, setttywidth);
+#ifdef __GNUC__ /* XXX: to shut up gcc warnings */
+ (void)&argc;
+ (void)&argv;
+#endif
+
if (argc > 0) {
if (strchr(argv[0], ':') != NULL) {
anonftp = 1; /* Handle "automatic" transfers. */
@@ -361,7 +369,7 @@ cmdscanner(top)
fputs("sorry, input line too long.\n", ttyout);
break;
}
- memcpy(line, buf, num);
+ memcpy(line, buf, (size_t)num);
line[num] = '\0';
history(hist, H_ENTER, buf);
}
diff --git a/usr.bin/ftp/ruserpass.c b/usr.bin/ftp/ruserpass.c
index fd9d5789a1d..eb9f08e5fc8 100644
--- a/usr.bin/ftp/ruserpass.c
+++ b/usr.bin/ftp/ruserpass.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: ruserpass.c,v 1.8 1997/04/23 20:33:21 deraadt Exp $ */
-/* $NetBSD: ruserpass.c,v 1.13 1997/04/01 14:20:34 mrg Exp $ */
+/* $OpenBSD: ruserpass.c,v 1.9 1997/07/25 21:56:22 millert Exp $ */
+/* $NetBSD: ruserpass.c,v 1.14 1997/07/20 09:46:01 lukem Exp $ */
/*
* Copyright (c) 1985, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95";
#else
-static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.8 1997/04/23 20:33:21 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.9 1997/07/25 21:56:22 millert Exp $";
#endif
#endif /* not lint */
@@ -133,12 +133,14 @@ next:
goto match;
if ((tmp = strchr(hostname, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
- strncasecmp(hostname, tokval, tmp-hostname) == 0 &&
+ strncasecmp(hostname, tokval,
+ (size_t)(tmp - hostname)) == 0 &&
tokval[tmp - hostname] == '\0')
goto match;
if ((tmp = strchr(host, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
- strncasecmp(host, tokval, tmp - host) == 0 &&
+ strncasecmp(host, tokval,
+ (size_t)(tmp - host)) == 0 &&
tokval[tmp - host] == '\0')
goto match;
continue;
diff --git a/usr.bin/ftp/stringlist.c b/usr.bin/ftp/stringlist.c
index a95735dd11f..9abfc540ad5 100644
--- a/usr.bin/ftp/stringlist.c
+++ b/usr.bin/ftp/stringlist.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stringlist.c,v 1.1 1997/02/03 01:05:44 millert Exp $ */
+/* $OpenBSD: stringlist.c,v 1.2 1997/07/25 21:56:23 millert Exp $ */
/* $NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $ */
/*
@@ -33,7 +33,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: stringlist.c,v 1.1 1997/02/03 01:05:44 millert Exp $";
+static char *rcsid = "$OpenBSD: stringlist.c,v 1.2 1997/07/25 21:56:23 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -53,13 +53,13 @@ sl_init()
{
StringList *sl = malloc(sizeof(StringList));
if (sl == NULL)
- _err(1, "stringlist: %m");
+ err(1, "stringlist: %m");
sl->sl_cur = 0;
sl->sl_max = _SL_CHUNKSIZE;
sl->sl_str = malloc(sl->sl_max * sizeof(char *));
if (sl->sl_str == NULL)
- _err(1, "stringlist: %m");
+ err(1, "stringlist: %m");
return sl;
}
@@ -76,7 +76,7 @@ sl_add(sl, name)
sl->sl_max += _SL_CHUNKSIZE;
sl->sl_str = realloc(sl->sl_str, sl->sl_max * sizeof(char *));
if (sl->sl_str == NULL)
- _err(1, "stringlist: %m");
+ err(1, "stringlist: %m");
}
sl->sl_str[sl->sl_cur++] = name;
}
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index 7a0f9325d54..eac3961b521 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: util.c,v 1.10 1997/06/10 19:39:54 millert Exp $ */
-/* $NetBSD: util.c,v 1.7 1997/04/14 09:09:24 lukem Exp $ */
+/* $OpenBSD: util.c,v 1.11 1997/07/25 21:56:23 millert Exp $ */
+/* $NetBSD: util.c,v 1.11 1997/07/21 14:03:49 lukem Exp $ */
/*
* Copyright (c) 1985, 1989, 1993, 1994
@@ -35,7 +35,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: util.c,v 1.10 1997/06/10 19:39:54 millert Exp $";
+static char rcsid[] = "$OpenBSD: util.c,v 1.11 1997/07/25 21:56:23 millert Exp $";
#endif /* not lint */
/*
@@ -49,6 +49,7 @@ static char rcsid[] = "$OpenBSD: util.c,v 1.10 1997/06/10 19:39:54 millert Exp $
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <glob.h>
#include <pwd.h>
#include <signal.h>
@@ -71,7 +72,7 @@ setpeer(argc, argv)
char *argv[];
{
char *host;
- short port;
+ in_port_t port;
if (connected) {
fprintf(ttyout, "Already connected to %s, use close first.\n",
@@ -88,14 +89,19 @@ setpeer(argc, argv)
}
port = ftpport;
if (argc > 2) {
- port = atoi(argv[2]);
- if (port <= 0) {
- fprintf(ttyout, "%s: bad port number '%s'.\n", argv[1], argv[2]);
- fprintf(ttyout, "usage: %s host-name [port]\n", argv[0]);
+ char *ep;
+ long nport;
+
+ nport = strtol(argv[2], &ep, 10);
+ if (nport < 1 || nport > 0xffff || *ep != '\0') {
+ fprintf(ttyout, "%s: bad port number '%s'.\n",
+ argv[1], argv[2]);
+ fprintf(ttyout, "usage: %s host-name [port]\n",
+ argv[0]);
code = -1;
return;
}
- port = htons(port);
+ port = htons((in_port_t)nport);
}
host = hookup(argv[1], port);
if (host) {
@@ -183,7 +189,7 @@ login(host, user, pass)
char *acct;
char anonpass[MAXLOGNAME + 1 + MAXHOSTNAMELEN]; /* "user@hostname" */
char hostname[MAXHOSTNAMELEN];
- int n, aflag, retry = 0;
+ int n, aflag = 0, retry = 0;
acct = NULL;
if (user == NULL) {
@@ -220,13 +226,12 @@ login(host, user, pass)
user, hp->h_name);
#endif
pass = anonpass;
- user = "ftp";
+ user = "anonymous"; /* as per RFC 1635 */
}
tryagain:
-
if (retry)
- user = "anonymous";
+ user = "ftp"; /* some servers only allow "ftp" */
while (user == NULL) {
char *myname = getlogin();
@@ -303,7 +308,7 @@ another(pargc, pargv, prompt)
}
fprintf(ttyout, "(%s) ", prompt);
line[len++] = ' ';
- if (fgets(&line[len], sizeof(line) - len, stdin) == NULL)
+ if (fgets(&line[len], (int)(sizeof(line) - len), stdin) == NULL)
intr();
len += strlen(&line[len]);
if (len > 0 && line[len - 1] == '\n')
@@ -481,11 +486,19 @@ remotesize(file, noisy)
size = -1;
if (debug == 0)
verbose = -1;
- if (command("SIZE %s", file) == COMPLETE)
- sscanf(reply_string, "%*s %qd", &size);
- else if (noisy && debug == 0) {
+ if (command("SIZE %s", file) == COMPLETE) {
+ char *cp, *ep;
+
+ cp = strchr(reply_string, ' ');
+ if (cp != NULL) {
+ cp++;
+ size = strtoq(cp, &ep, 10);
+ if (*ep != '\0' && !isspace(*ep))
+ size = -1;
+ }
+ } else if (noisy && debug == 0) {
fputs(reply_string, ttyout);
- fputs("\n", ttyout);
+ fputc('\n', ttyout);
}
verbose = overbose;
return (size);
@@ -526,7 +539,7 @@ remotemodtime(file, noisy)
rtime += timebuf.tm_gmtoff; /* conv. local -> GMT */
} else if (noisy && debug == 0) {
fputs(reply_string, ttyout);
- fputs("\n", ttyout);
+ fputc('\n', ttyout);
}
verbose = overbose;
return (rtime);
@@ -548,8 +561,11 @@ foregroundproc()
ctty_pgrp == pgrp));
}
+void updateprogressmeter __P((int));
+
void
-updateprogressmeter()
+updateprogressmeter(dummy)
+ int dummy;
{
if (foregroundproc())
@@ -618,7 +634,7 @@ progressmeter(flag)
abbrevsize >>= 10;
}
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- " %5qd %c%c ", abbrevsize, prefixes[i],
+ " %5qd %c%c ", (quad_t)abbrevsize, prefixes[i],
prefixes[i] == ' ' ? ' ' : 'B');
timersub(&now, &lastupdate, &wait);
@@ -635,7 +651,7 @@ progressmeter(flag)
timersub(&now, &start, &td);
elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
- if (bytes <= 0 || elapsed <= 0.0) {
+ if (bytes <= 0 || elapsed <= 0.0 || cursize > filesize) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
" --:-- ETA");
} else if (wait.tv_sec >= STALLTIME) {
@@ -697,13 +713,15 @@ ptransfer(siginfo)
meg = 1;
(void)snprintf(buf, sizeof(buf),
"%qd byte%s %s in %.2f seconds (%.2f %sB/s)\n",
- bytes, bytes == 1 ? "" : "s", direction, elapsed,
+ (quad_t)bytes, bytes == 1 ? "" : "s", direction, elapsed,
bs / (1024.0 * (meg ? 1024.0 : 1.0)), meg ? "M" : "K");
- if (siginfo && bytes > 0 && elapsed > 0.0 && filesize >= 0) {
+ if (siginfo && bytes > 0 && elapsed > 0.0 && filesize >= 0
+ && bytes + restart_point <= filesize) {
remaining = (int)((filesize - restart_point) /
(bytes / elapsed) - elapsed);
hh = remaining / 3600;
remaining %= 3600;
+ /* "buf+len(buf) -1" to overwrite \n */
snprintf(buf + strlen(buf) - 1, sizeof(buf) - strlen(buf),
" ETA: %02d:%02d:%02d\n", hh, remaining / 60,
remaining % 60);