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 <sitsofe@yahoo.com>
iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, N2S_NONE);
}
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,
if (je->rate[DDIR_TRIM] || je->iops[DDIR_TRIM])
l = snprintf(p, left,
rate_str[DDIR_READ], rate_str[DDIR_WRITE],
iops_str[DDIR_READ], iops_str[DDIR_WRITE],
eta_str);
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, "");
p += l;
if (l >= 0 && l < linelen_last)
p += sprintf(p, "%*s", linelen_last - l, "");