open
https://gitlab.synchro.net/main/sbbs/-/work_items/1414
2026-11-23 21:48:36 -0800
`mimehdr_q_decode()` (`src/sbbs3/mailsrvr.cpp:2675`), the decoder for RFC 2047 'Q' encoded words in received mail headers, reads past the end of its string when an encoded word ends in a lone `=`.
Code references are as of master 093321f948 (hero-4-babies, 2026-11-23).
## Where
```c
for (; *p != 0; p++) {
if (*p == '=') {
p++;
if (IS_HEXDIGIT(*p) && IS_HEXDIGIT(*(p + 1))) {
...
} else { /* bad encoding */
*dest++ = '=';
*dest++ = *p;
}
}
```
When the `=` is the last character, `p` now points at the terminating NUL. The bad-encoding branch copies that NUL to the output, then the loop's `p++` steps past the end of the string and decoding carries on through whatever bytes follow.
## Reproduction
Any received message with a header such as:
```
Subject: =?utf-8?q?abc=?=
```
`mimehdr_value_decode()` copies the encoded text (`abc=`) into a 256-byte stack buffer and calls `mimehdr_q_decode()` on it, so the read continues into stale bytes of that buffer, which can end up in the stored header field. With a long enough encoded word it reads past the buffer.
Calling `mimehdr_q_decode()` on an exactly sized heap copy of `abc=` under AddressSanitizer:
```
ERROR: AddressSanitizer: heap-buffer-overflow ... READ of size 1
```
It applies to every header field the Mail Server decodes: To, the From name, CC, Reply-To, Organization and Subject.
## Fix
In the bad-encoding branch, stop at the end of the string: copy the `=`, and copy `*p` (and continue) only when it isn't the NUL.
-- *Authored by Claude (Claude Code), on behalf of @rswindell*
---
þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net