Hi, When using address sanitizer, there is many occurrences of this error:
$ grep -r 521 tests/ tests/testsuite.dir/002/testsuite.log:+ #0 0x4694f0 in code_ns_fraction /home/collin/.local/src/tar/src/misc.c:521 tests/testsuite.dir/002/testsuite.log:+SUMMARY: AddressSanitizer: stack-buffer-overflow /home/collin/.local/src/tar/src/misc.c:521 in code_ns_fraction tests/testsuite.dir/026/testsuite.log:+ #0 0x4694f0 in code_ns_fraction /home/collin/.local/src/tar/src/misc.c:521 tests/testsuite.dir/026/testsuite.log:+SUMMARY: AddressSanitizer: stack-buffer-overflow /home/collin/.local/src/tar/src/misc.c:521 in code_ns_fraction [....] It seems that the definition of 'TIMESPEC_STRSIZE_BOUND' doesn't account for the NUL byte. I've attached a fix. Collin
>From d4d02be605a1e183dfeabb0515455b4718ca2efe Mon Sep 17 00:00:00 2001 From: Collin Funk <collin.fu...@gmail.com> Date: Sat, 21 Sep 2024 22:42:42 -0700 Subject: [PATCH] Fix off-by-one error. * src/common.h (TIMESPEC_STRSIZE_BOUND): Account for NUL. --- src/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index 07ac5fc7..bfb8cf43 100644 --- a/src/common.h +++ b/src/common.h @@ -697,7 +697,7 @@ char *timetostr (time_t, char buf[SYSINT_BUFSIZE]); void code_ns_fraction (int ns, char *p); enum { BILLION = 1000000000, LOG10_BILLION = 9 }; enum { TIMESPEC_STRSIZE_BOUND = - SYSINT_BUFSIZE + LOG10_BILLION + sizeof "." - 1 }; + SYSINT_BUFSIZE + LOG10_BILLION + sizeof "." }; char const *code_timespec (struct timespec ts, char tsbuf[TIMESPEC_STRSIZE_BOUND]); struct timespec decode_timespec (char const *, char **, bool); -- 2.46.1