summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2001-08-21 11:39:32 +0000
committerbrian <brian@FreeBSD.org>2001-08-21 11:39:32 +0000
commit30830b42926a66f348cb4d1deb534a02a428f1ed (patch)
tree9d4fd0ecdbfe74ad84e5c3250ad4bdd49537cdda
parent20971d752c9fe30b7e67b7e8053e5587320f878d (diff)
downloadFreeBSD-src-30830b42926a66f348cb4d1deb534a02a428f1ed.zip
FreeBSD-src-30830b42926a66f348cb4d1deb534a02a428f1ed.tar.gz
Handle overflows from snprintf(), not just returns of < 0
Pointed out by: bde
-rw-r--r--usr.bin/ftp/util.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index 1936baf..89f16f5 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -624,7 +624,7 @@ progressmeter(flag)
ratio = MAX(ratio, 0);
ratio = MIN(ratio, 100);
n = snprintf(buf + len, sizeof(buf) - len, "\r%3d%% ", ratio);
- if (n > 0)
+ if (n > 0 || len < sizeof(buf) - len)
len += n;
barlength = ttywidth - 30;
@@ -635,7 +635,7 @@ progressmeter(flag)
"*****************************************************************************"
"*****************************************************************************",
barlength - i, "");
- if (n > 0)
+ if (n > 0 || len < sizeof(buf) - len)
len += n;
}
@@ -648,7 +648,7 @@ progressmeter(flag)
n = snprintf(buf + len, sizeof(buf) - len,
" %5qd %c%c ", (long long)abbrevsize, prefixes[i],
prefixes[i] == ' ' ? ' ' : 'B');
- if (n > 0)
+ if (n > 0 || len < sizeof(buf) - len)
len += n;
timersub(&now, &lastupdate, &wait);
@@ -685,14 +685,14 @@ progressmeter(flag)
else
n = snprintf(buf + len, sizeof(buf) - len,
" ");
- if (n > 0)
+ if (n > 0 || len < 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)
+ if (n > 0 || len < sizeof(buf) - len)
len += n;
(void)write(STDOUT_FILENO, buf, len);
OpenPOWER on IntegriCloud