summaryrefslogtreecommitdiff
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authorBrian Somers <brian@FreeBSD.org>2001-08-23 12:53:15 +0000
committerBrian Somers <brian@FreeBSD.org>2001-08-23 12:53:15 +0000
commit0baa3ca4502b9f57e65d484969b81be6995f7cb5 (patch)
tree4424cae5f4353213d26294ba4bc6379440a8d168 /usr.bin/ftp
parent4132a3b2066cab89e73724231d424c12ead6f938 (diff)
downloadsrc-test-0baa3ca4502b9f57e65d484969b81be6995f7cb5.tar.gz
src-test-0baa3ca4502b9f57e65d484969b81be6995f7cb5.zip
Fix my previous snprintf() patches (which were largely no-ops).
Mostly submitted by: bde
Notes
Notes: svn path=/head/; revision=82187
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/fetch.c4
-rw-r--r--usr.bin/ftp/util.c16
2 files changed, 11 insertions, 9 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index 31d5649b8b42d..f833f01f5a080 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -282,11 +282,11 @@ url_get(origline, proxyenv)
printf("Requesting %s (via %s)\n", origline, proxyenv);
len = snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n",
proxy ? "" : "/", path);
- if (len < 0) {
+ if (len < 0 || len >= sizeof(buf)) {
warnx("Failed to format HTTP request");
goto cleanup_url_get;
}
- if (write(s, buf, len) < len) {
+ if (write(s, buf, len) < len) {
warn("Writing HTTP request");
goto cleanup_url_get;
}
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index 89f16f5e9ae24..60481910c3425 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -624,18 +624,20 @@ progressmeter(flag)
ratio = MAX(ratio, 0);
ratio = MIN(ratio, 100);
n = snprintf(buf + len, sizeof(buf) - len, "\r%3d%% ", ratio);
- if (n > 0 || len < sizeof(buf) - len)
+ if (n > 0 && n < sizeof(buf) - len)
len += n;
barlength = ttywidth - 30;
if (barlength > 0) {
+ if (barlength > 154)
+ barlength = 154; /* Number of '*'s below */
i = barlength * ratio / 100;
n = snprintf(buf + len, sizeof(buf) - len,
"|%.*s%*s|", i,
"*****************************************************************************"
"*****************************************************************************",
barlength - i, "");
- if (n > 0 || len < sizeof(buf) - len)
+ if (n > 0 && n < sizeof(buf) - len)
len += n;
}
@@ -648,7 +650,7 @@ progressmeter(flag)
n = snprintf(buf + len, sizeof(buf) - len,
" %5qd %c%c ", (long long)abbrevsize, prefixes[i],
prefixes[i] == ' ' ? ' ' : 'B');
- if (n > 0 || len < sizeof(buf) - len)
+ if (n > 0 && n < sizeof(buf) - len)
len += n;
timersub(&now, &lastupdate, &wait);
@@ -685,14 +687,14 @@ progressmeter(flag)
else
n = snprintf(buf + len, sizeof(buf) - len,
" ");
- if (n > 0 || len < sizeof(buf) - len)
+ if (n > 0 && n < sizeof(buf) - len)
len += n;
i = remaining % SECSPERHOUR;
len += snprintf(buf + len, sizeof(buf) - len,
"%02d:%02d ETA", i / 60, i % 60);
}
}
- if (n > 0 || len < sizeof(buf) - len)
+ if (n > 0 && n < sizeof(buf) - len)
len += n;
(void)write(STDOUT_FILENO, buf, len);
@@ -739,7 +741,7 @@ ptransfer(siginfo)
"%qd byte%s %s in %.2f seconds (%.2f %sB/s)\n",
(long long)bytes, bytes == 1 ? "" : "s", direction, elapsed,
bs / (1024.0 * (meg ? 1024.0 : 1.0)), meg ? "M" : "K");
- if (n > 0)
+ if (n > 0 && n < sizeof(buf) - len)
len += n;
if (siginfo && bytes > 0 && elapsed > 0.0 && filesize >= 0
&& bytes + restart_point <= filesize) {
@@ -751,7 +753,7 @@ ptransfer(siginfo)
n = snprintf(buf + len, sizeof(buf) - len,
" ETA: %02d:%02d:%02d\n", hh, remaining / 60,
remaining % 60);
- if (n > 0)
+ if (n > 0 && n < sizeof(buf) - len)
len += n;
}
(void)write(siginfo ? STDERR_FILENO : STDOUT_FILENO, buf, len);