https://gitlab.synchro.net/main/sbbs/-/commit/e74c597f37ef4e4cc4651bec
Added Files:
exec/tests/msgbase/long_msgid.js
Modified Files:
src/sbbs3/js_msgbase.cpp msg_id.c
Log Message:
get_msgid(): terminate the caller's buffer
When the message has a Message-ID of its own, get_msgid() copied it to
the caller's buffer with strncpy() and returned the message's own
pointer. strncpy() does not terminate the buffer when the ID is as long
as the buffer or longer, so every caller that uses the buffer rather than
the return value read past its end. The MsgBase header object's "id"
property was one: for a stored Message-ID of 256 bytes or more it was the
first 256 bytes followed by whatever followed the 256-byte buffer on the
stack, up to the next NUL. This has been so since get_msgid() took a
caller's buffer, in 73134a2c86 (items-12-quick, 2008-02-25).
get_msgid() now copies with strlcpy(), so the buffer is always
terminated (and truncated to fit), and still returns the message's own
ID in full. The "id" property now takes the return value, so it is the
whole Message-ID, however long. The other callers that use the buffer
get a terminated, truncated ID: get_replyid() (the Reply-ID of a new
reply, when the message replied to has an ID that long) and the QWK
export's Message-ID and voting lines. Callers that use the return value
(the mail server's Message-ID header and bounce message) are unchanged,
and so are the paths that generate an ID, which always terminate.
Reproduced and verified with the new test
exec/tests/msgbase/long_msgid.js (IDs of 100, 255, 256 and 300 bytes
saved to a scratch base opened by path and read back through
get_msg_header(), expanded and not, and get_all_msg_headers(); before,
the 300-byte ID read back as 256 bytes), and with AddressSanitizer on a
small harness linking msg_id.c: before, a stack-buffer-overflow (a
257-byte read of the 256-byte buffer); after, a 255-byte terminated
string.
Built and tested with GCC only.
Co-Authored-By: Claude Fable 5.2 <
noreply@anthropic.com>