Mark Esler [Sat, 7 Mar 2026 03:09:24 +0000 (19:09 -0800)]
lib-mail: mbox_from_parse() - Fix bounds check in time parsing
Add bounds checks before hour/minute parsing (msg + 5 > msg_end)
and before optional seconds parsing (msg + 3 > msg_end). The
alt_stamp path consumes a variable number of bytes for the day
field, which can exhaust the initial budget before reaching the
time section.
Also guard the optional seconds entry with msg >= msg_end to
handle truncated inputs that end after minutes.
Found by fuzzing with libFuzzer and AddressSanitizer.
Timo Sirainen [Thu, 12 Mar 2026 09:13:20 +0000 (11:13 +0200)]
lib-mail: mbox_from_parse() - Fix bounds check in named timezone
The named timezone check reads msg[0] through msg[3] without
verifying 4 bytes remain. The else-if branch below reads msg[0]
through msg[5]. When optional seconds consume the initial budget,
this reads past the buffer.
Mark Esler [Fri, 6 Mar 2026 07:03:40 +0000 (23:03 -0800)]
lib-mail: mbox_from_parse() - Fix bounds check in trailing timezone
The trailing timezone check used msg != msg_end before reading
msg[0] through msg[5]. When fewer than 6 bytes remain, this
reads past the buffer. Replace with msg + 6 <= msg_end.
Found by fuzzing with libFuzzer and AddressSanitizer.
Dexter.k [Fri, 20 Feb 2026 09:34:13 +0000 (09:34 +0000)]
global: Replace open-coded allocation size arithmetic with overflow-safe helpers
Replace several instances of multi-term allocation size arithmetic
(e.g. a + b + c) with small helper MALLOC_ADD3() macro built on
existing MALLOC_ADD().
This keeps overflow handling centralized, improves consistency across
the codebase, and makes size computations easier to audit.
Timo Sirainen [Sat, 28 Feb 2026 08:32:15 +0000 (10:32 +0200)]
lib-charset: Increase CHARSET_MAX_PENDING_BUF_SIZE to 16 bytes
The old 10 bytes is likely enough, but lets make it safer based on AI's
recommendation:
While the 4–8 byte rule covers most common encodings, ISO-2022 variants
(like ISO-2022-JP) are the primary reason you might need a slightly larger
buffer. Because these encodings use multi-byte "escape sequences" to switch
between character sets, iconv() may stop mid-sequence.
For standard ISO-2022 variants, a buffer of 10 to 16 bytes is generally
considered the absolute "safe" maximum for unconverted bytes.
Why 16 Bytes? While individual characters or escape sequences rarely exceed
4–6 bytes, choosing 16 bytes provides a power-of-two alignment that safely
handles even the most obscure registered ISO-IR sequences and provides a
margin for implementation-specific behavior.
Timo Sirainen [Sat, 28 Feb 2026 08:27:19 +0000 (10:27 +0200)]
lib-mail: Reset charset translation buffer between MIME parts
If MIME part ended with an incomplete charset translation, the buffer was
kept for the next MIME part. This could have produced garbage in the next
MIME part, or a crash.
Timo Sirainen [Thu, 26 Feb 2026 10:29:12 +0000 (12:29 +0200)]
lib: Preserve errno in our malloc() and free() wrappers
Various places assume that e.g. t_strdup_printf() calls and such don't
modify errno. But because they internally call malloc() or calloc(), this
isn't actually guaranteed now and it can happen at least with newer glibc
versions. Explicitly preserve the errno for these calls where it might
be a problem.
Timo Sirainen [Tue, 24 Feb 2026 20:49:43 +0000 (22:49 +0200)]
master: Don't check default_login_user and default_internal_user existence in config parsing
In some situations the check may run with default settings, even if the
settings have been changed in config file, which results in causing a
failure if the default users don't exist.
Stephan Bosch [Wed, 15 Nov 2023 03:16:09 +0000 (04:16 +0100)]
lib-compression: istream-decompress - Fix hangs when stream is used in asynchronous context
Do not call i_stream_read() blindly. Make sure that if it is called, it's return
value is always evaluated, because otherwise data might get stalled in the
stream while no more input events are incoming; this causes a hang in
asynchronous contexts.
Timo Sirainen [Fri, 20 Feb 2026 11:20:39 +0000 (13:20 +0200)]
lib: timeval_add/sub_usecs() - Fix usecs type
Some callers expect it to be 64bit, but suseconds_t isn't guaranteed to be.
Added assert mainly to catch callers that try to provide negative values
as parameter, which wrap to large unsigned values.
Stephan Bosch [Fri, 13 Feb 2026 21:57:32 +0000 (22:57 +0100)]
lib: unicode-transform - Fix panic caused by Stream-Safe Text Process encountering composed non-starters
UAX15-D4: Stream-Safe Text Process is the process of producing a Unicode string
in Stream-Safe Text Format by processing that string from start to finish,
inserting U+034F COMBINING GRAPHEME JOINER (CGJ) within long sequences of
non-starters.
The current implementation did not properly account for composed non-starters,
which decompose in more than a single code point. This is something not
found in normal valid Unicode text. This could trigger one of two assert
failures, because these asserts did not account for the buffer
still being full at a second attempt.