On Mon, Nov 24, 2025 at 03:26:52PM -0500, Noah Meyerhans via dovecot wrote:
The build failure was introduced with commit 41bd7a502 ("lib-settings, config: Use native CPU endianess in binary config file"). The build is successful at the previous commit, but fails at that commit.
I haven't yet determined whether the failure is with the code itself or the test.
Looked into this a little deeper. The behavior of the following code (from lib-settings/settings.c) varies based on the endianness of the host:
/* Verify that block ends with NUL. This way we can safely use strlen()
later on and we know it won't read past the mmaped memory area and
cause a crash. The NUL is either from the last settings value or
from the last error string. */
if (((const char *)mmap->mmap_base)[block_end_offset-1] != '\0') {
*error_r = t_strdup_printf(
"Settings block doesn't end with NUL at offset %zu",
block_end_offset-1);
return -1;
}
With the test data provided in test-master-service-settings.c, this condition passes and the conditional block runs on big endian systems. The condition fails and the inner block is skipped on little endian systems only by coincidence.
On little endian, the last field in the provided input NUM32("\x01") encodes to "\x01\x00\x00\x00" on little endian systems, so the last byte happens to be null. On big endian, the same data is encoded as "\x00\x00\x00\x01", so the last byte is "\x01", which is not null.
IMO the fact that this test is actually passing on little endian is a problem. The code is looking for a trailing null, which it finds, but that just happens to be a random null byte in a truncated data stream. The input data is binary, consisting of 64-bit and 32-bit numbers in addition to byte values. The fact that the above check can pass on truncated or otherwise corrupt input data that just happens to end in a null byte suggests that it's not a particularly useful validity test.
Of course, there are several more validity checks in settings_block_read() and elsewhere, so maybe we can reliably detect other forms of corruption elsewhere?
noah