eta: fix previous line length calculation
authorSitsofe Wheeler <sitsofe@yahoo.com>
Sat, 23 Dec 2017 08:43:54 +0000 (08:43 +0000)
committerSitsofe Wheeler <sitsofe@yahoo.com>
Sun, 24 Dec 2017 23:34:39 +0000 (23:34 +0000)
commit45d41a8b4a338404b838e6e5dcae376159d8dfb9
tree24e4d2a49492481190f9a0602bf5034d133c829e
parentab1ace6229f9f2e0b5e592b42f5cde4c29ff1a38
eta: fix previous line length calculation

We work out how many stale characters we haven't yet overprinted from
the previous run by comparing the number of characters that snprintf
added to the buffer in both cases. Unfortunately this doesn't account
for earlier characters that may (or may not) have already been in the
output buffer before snprintf was called...

Change the code to just use the current and previous output buffer
position to calculate the remainder of the line to be cleared.

When fio is compiled under clang with
./configure --extra-cflags="-fsanitize=address -fno-builtin" \
 --disable-optimizations

a buffer overrun is demonstrated by the following script

rw[0]='read'; rw[1]='write'; \
for i in {1..4096}; do \
  echo -e "[job$i]\nrw=${rw[$((i % 2))]}\n" \
  "ramp_time=$(((4096 - i) / 2049 * 10))\n" \
          "runtime=15"; \
done | \
./fio --group_reporting --ioengine=null --size=1g --time_based \
 --bs=512 --thread --rate_iops=2 -

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
eta.c