]> git.ipfire.org Git - thirdparty/git.git/commit
fsck: avoid parse_timestamp() on buffer that isn't NUL-terminated
authorJeff King <peff@peff.net>
Tue, 18 Nov 2025 09:12:28 +0000 (04:12 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Nov 2025 17:36:12 +0000 (09:36 -0800)
commit5a993593b24df699f60841296795f9a6ca60d399
tree071af353f88204b9b150106d6a638cf78b8e6ac9
parentf05df7ffca492b37d604ad6beed788055eb56ebd
fsck: avoid parse_timestamp() on buffer that isn't NUL-terminated

In fsck_ident(), we parse the timestamp with parse_timestamp(), which is
really an alias for strtoumax(). But since our buffer may not be
NUL-terminated, this can trigger a complaint from ASan's
strict_string_checks mode. This is a false positive, since we know that
the buffer contains a trailing newline (which we checked earlier in the
function), and that strtoumax() would stop there.

But it is worth working around ASan's complaint. One is because that
will let us turn on strict_string_checks by default, which has helped
catch other real problems. And two is that the safety of the current
code is very hard to reason about (it subtly depends on distant code
which could change).

One option here is to just parse the number left-to-right ourselves. But
we care about the size of a timestamp_t and detecting overflow, since
that's part of the point of these checks. And doing that correctly is
tricky. So we'll instead just pull the digits into a separate,
NUL-terminated buffer, and use that to call parse_timestamp().

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsck.c