diff options
author | brian <brian@FreeBSD.org> | 2001-08-23 12:53:15 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2001-08-23 12:53:15 +0000 |
commit | 4fa1bbf1c3268dcdda965bc166719f4f402ff953 (patch) | |
tree | 4424cae5f4353213d26294ba4bc6379440a8d168 /usr.bin | |
parent | f53d43761e663beb3f653487123cf4a929573e3f (diff) | |
download | FreeBSD-src-4fa1bbf1c3268dcdda965bc166719f4f402ff953.zip FreeBSD-src-4fa1bbf1c3268dcdda965bc166719f4f402ff953.tar.gz |
Fix my previous snprintf() patches (which were largely no-ops).
Mostly submitted by: bde
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ftp/fetch.c | 4 | ||||
-rw-r--r-- | usr.bin/ftp/util.c | 16 |
2 files changed, 11 insertions, 9 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 31d5649..f833f01 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 89f16f5..6048191 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); |