summaryrefslogtreecommitdiffstats
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authormike <mike@FreeBSD.org>2001-08-29 23:51:14 +0000
committermike <mike@FreeBSD.org>2001-08-29 23:51:14 +0000
commitb093d3a26eaec4180495d37ba8e76768301f3b2d (patch)
treec48af1237f4e5ae72678b12e80086ec5acb0ee37 /usr.bin/ftp
parentca93e132a40987f527cf6023647c4a067283a0f5 (diff)
downloadFreeBSD-src-b093d3a26eaec4180495d37ba8e76768301f3b2d.zip
FreeBSD-src-b093d3a26eaec4180495d37ba8e76768301f3b2d.tar.gz
o Fix some checks on snprintf(3) to prevent miscalculations.
o This fixes a memory leak that can occur on some URL's. Pointy hat to: brian
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/util.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index 6048191..3c1d49a 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -670,16 +670,22 @@ progressmeter(flag)
if (bytes <= 0 || elapsed <= 0.0 || cursize > filesize) {
n = snprintf(buf + len, sizeof(buf) - len,
" --:-- ETA");
+ if (n > 0 && n < sizeof(buf) - len)
+ len += n;
} else if (wait.tv_sec >= STALLTIME) {
n = snprintf(buf + len, sizeof(buf) - len,
" - stalled -");
+ if (n > 0 && n < sizeof(buf) - len)
+ len += n;
} else {
remaining =
((filesize - restart_point) / (bytes / elapsed) - elapsed);
- if (remaining >= 100 * SECSPERHOUR)
+ if (remaining >= 100 * SECSPERHOUR) {
n = snprintf(buf + len, sizeof(buf) - len,
" --:-- ETA");
- else {
+ if (n > 0 && n < sizeof(buf) - len)
+ len += n;
+ } else {
i = remaining / SECSPERHOUR;
if (i)
n = snprintf(buf + len, sizeof(buf) - len,
@@ -694,8 +700,6 @@ progressmeter(flag)
"%02d:%02d ETA", i / 60, i % 60);
}
}
- if (n > 0 && n < sizeof(buf) - len)
- len += n;
(void)write(STDOUT_FILENO, buf, len);
if (flag == -1) {
OpenPOWER on IntegriCloud