diff options
author | mike <mike@FreeBSD.org> | 2001-08-29 23:51:14 +0000 |
---|---|---|
committer | mike <mike@FreeBSD.org> | 2001-08-29 23:51:14 +0000 |
commit | b093d3a26eaec4180495d37ba8e76768301f3b2d (patch) | |
tree | c48af1237f4e5ae72678b12e80086ec5acb0ee37 /usr.bin | |
parent | ca93e132a40987f527cf6023647c4a067283a0f5 (diff) | |
download | FreeBSD-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')
-rw-r--r-- | usr.bin/ftp/util.c | 12 |
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) { |