From: Sitsofe Wheeler Date: Fri, 22 Dec 2017 11:10:35 +0000 (+0000) Subject: eta: adjust truncation case X-Git-Tag: fio-3.4~35^2~4 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=38aef42dad8d84cdf9a3fd4efb2db93868377fd3;p=fio.git eta: adjust truncation case c076de85fa4901683f6ce23ecdc071c17801ffad ("eta: fix buffer overflow in ETA output") made adjustments to cope with snprintf truncation. However since we're replacing the null added by snprintf, left only needs to be one smaller than the output buffer. Make this change and add a comment about what we're doing. Signed-off-by: Sitsofe Wheeler --- diff --git a/eta.c b/eta.c index 087f57d9..a156559f 100644 --- a/eta.c +++ b/eta.c @@ -585,7 +585,7 @@ void display_thread_status(struct jobs_eta *je) iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, N2S_NONE); } - left = sizeof(output) - (p - output) - 2; + left = sizeof(output) - (p - output) - 1; if (je->rate[DDIR_TRIM] || je->iops[DDIR_TRIM]) l = snprintf(p, left, @@ -601,8 +601,9 @@ void display_thread_status(struct jobs_eta *je) rate_str[DDIR_READ], rate_str[DDIR_WRITE], iops_str[DDIR_READ], iops_str[DDIR_WRITE], eta_str); - if (l > left) - l = left; + /* If truncation occurred adjust l so p is on the null */ + if (l >= left) + l = left - 1; p += l; if (l >= 0 && l < linelen_last) p += sprintf(p, "%*s", linelen_last - l, "");