Skip to content

dbfile: zero-initialise the uuid buffer in __dbfile_get_config - #414

Open
martinus wants to merge 1 commit into
markfasheh:masterfrom
martinus:backport/uninit-uuid-read
Open

dbfile: zero-initialise the uuid buffer in __dbfile_get_config#414
martinus wants to merge 1 commit into
markfasheh:masterfrom
martinus:backport/uninit-uuid-read

Conversation

@martinus

Copy link
Copy Markdown

What this fixes

__dbfile_get_config() declares char uuid[37]; uninitialised, then fills it via get_config_text(stmt, "fs_uuid", uuid, 36). get_config_text() memcpy()s exactly len (36) bytes without writing a NUL terminator — and writes nothing at all if the fs_uuid config row is absent. It then calls uuid_parse(uuid, ...), which strlen()s its argument.

What happens without the fix

uuid_parse()'s strlen() runs past the 36-byte uuid into uninitialised stack (an uninitialised read — valgrind flags it on every config load). If the fs_uuid row is missing, the whole buffer is uninitialised and uuid_parse() can parse garbage over the default fs_uuid. In practice the trailing stack bytes are usually zero, so it silently "works" — but it's undefined behaviour.

The fix

Zero-initialise the buffer (char uuid[37] = "";) so it is always NUL-terminated regardless of what get_config_text() wrote.

Found via a valgrind sweep in the oans fork; the defect is inherited straight from here.

__dbfile_get_config() read an uninitialised buffer. get_config_text()
memcpy()s exactly `len` (36) bytes into the buffer without a NUL
terminator - and writes nothing at all when the config row is absent - so
uuid_parse()'s strlen() ran past the 36-byte uuid into uninitialised
stack, and on a missing config row could parse garbage over the default
fs_uuid. Zero-initialise the buffer so it is always terminated.

Harmless in practice (the trailing stack bytes were usually zero), but
it's a real uninitialised read - valgrind flags it on config load.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant