Bugzilla – Attachment 3676 Details for
Bug 3534
probable underflow calculating display width of file name
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Revised diff
bz3534.diff (text/plain), 3.36 KB, created by
Damien Miller
on 2023-02-15 20:16:07 AEDT
(
hide
)
Description:
Revised diff
Filename:
MIME Type:
Creator:
Damien Miller
Created:
2023-02-15 20:16:07 AEDT
Size:
3.36 KB
patch
obsolete
>diff --git a/progressmeter.c b/progressmeter.c >index 8baf798f1..f69f70662 100644 >--- a/progressmeter.c >+++ b/progressmeter.c >@@ -119,14 +119,14 @@ format_size(char *buf, int size, off_t bytes) > void > refresh_progress_meter(int force_update) > { >- char buf[MAX_WINSIZE + 1]; >+ char buf[MAX_WINSIZE + 1], buf2[MAX_WINSIZE + 1]; > off_t transferred; > double elapsed, now; > int percent; > off_t bytes_left; > int cur_speed; > int hours, minutes, seconds; >- int file_len; >+ int file_len, cols; > > if ((!force_update && !alarm_fired && !win_resized) || !can_output()) > return; >@@ -164,13 +164,22 @@ refresh_progress_meter(int force_update) > } else > bytes_per_second = cur_speed; > >+ last_update = now; >+ >+ /* Don't bother if we can't even display the percentage complete */ >+ if (win_size < 4) >+ return; >+ > /* filename */ >- buf[0] = '\0'; >- file_len = win_size - 36; >+ *buf = '\0'; >+ file_len = cols = win_size - 36; > if (file_len > 0) { >- buf[0] = '\r'; >- snmprintf(buf+1, sizeof(buf)-1, &file_len, "%-*s", >- file_len, file); >+ snmprintf(buf, sizeof(buf), &cols, "%-*s", file_len, file); >+ /* If we used fewer columns than expected then pad */ >+ if (cols < file_len) { >+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), >+ "%*s", file_len - cols, ""); >+ } > } > > /* percent of transfer done */ >@@ -178,18 +187,19 @@ refresh_progress_meter(int force_update) > percent = 100; > else > percent = ((float)cur_pos / end_pos) * 100; >- snprintf(buf + strlen(buf), win_size - strlen(buf), >+ >+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), > " %3d%% ", percent); > > /* amount transferred */ >- format_size(buf + strlen(buf), win_size - strlen(buf), >+ format_size(buf + strlen(buf), sizeof(buf) - strlen(buf), > cur_pos); >- strlcat(buf, " ", win_size); >+ strlcat(buf, " ", sizeof(buf)); > > /* bandwidth usage */ >- format_rate(buf + strlen(buf), win_size - strlen(buf), >+ format_rate(buf + strlen(buf), sizeof(buf) - strlen(buf), > (off_t)bytes_per_second); >- strlcat(buf, "/s ", win_size); >+ strlcat(buf, "/s ", sizeof(buf)); > > /* ETA */ > if (!transferred) >@@ -198,9 +208,9 @@ refresh_progress_meter(int force_update) > stalled = 0; > > if (stalled >= STALL_TIME) >- strlcat(buf, "- stalled -", win_size); >+ strlcat(buf, "- stalled -", sizeof(buf)); > else if (bytes_per_second == 0 && bytes_left) >- strlcat(buf, " --:-- ETA", win_size); >+ strlcat(buf, " --:-- ETA", sizeof(buf)); > else { > if (bytes_left > 0) > seconds = bytes_left / bytes_per_second; >@@ -213,20 +223,23 @@ refresh_progress_meter(int force_update) > seconds -= minutes * 60; > > if (hours != 0) >- snprintf(buf + strlen(buf), win_size - strlen(buf), >+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), > "%d:%02d:%02d", hours, minutes, seconds); > else >- snprintf(buf + strlen(buf), win_size - strlen(buf), >+ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), > " %02d:%02d", minutes, seconds); > > if (bytes_left > 0) >- strlcat(buf, " ETA", win_size); >+ strlcat(buf, " ETA", sizeof(buf)); > else >- strlcat(buf, " ", win_size); >+ strlcat(buf, " ", sizeof(buf)); > } > >- atomicio(vwrite, STDOUT_FILENO, buf, win_size - 1); >- last_update = now; >+ /* Finally, truncate string at window width */ >+ buf2[0] = '\r'; >+ cols = win_size - 1; >+ snmprintf(buf2 + 1, sizeof(buf2) - 1, &cols, "%s", buf); >+ atomicio(vwrite, STDOUT_FILENO, buf2, strlen(buf2)); > } > > /*ARGSUSED*/
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 3534
:
3665
|
3666
|
3667
|
3670
|
3674
|
3675
|
3676
|
3679
|
3680