• src/smblib/smblib.c

    From Rob Swindell (on Windows 11)@VERT to Git commit to main/sbbs/master on Fri Jan 16 20:45:33 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/5bd46a2ed2ff6bbc4aa2fb8a
    Modified Files:
    src/smblib/smblib.c
    Log Message:
    smb_lock(): Confirm the lock file exists after closing it and a short delay

    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
  • From Rob Swindell (on Debian Linux)@VERT to Git commit to main/sbbs/master on Mon May 11 23:57:27 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/931d45a1c1bd411af6c1c16c
    Modified Files:
    src/smblib/smblib.c
    Log Message:
    smb_new_msghdr: auto-repair small .sid/.shd status mismatches; check smb_putstatus return value

    Problem: if the .sid index file length didn't exactly match total_msgs * idxreclen, smb_new_msghdr returned SMB_ERR_FILE_LEN (-206) hard, blocking
    all further message adds until the msgbase was manually repaired. On 2026-05-09 this caused the mail SMB to reject every incoming message for
    ~14 hours (647 logged errors), resulting in SMTP "452 Insufficient system storage" responses.

    Root cause of the corruption: smb_putstatus() was called but its return
    value was silently discarded. If the status write failed after the index record was already appended to .sid, the two files diverged: .sid had one
    more record than total_msgs reflected (or vice-versa).

    Fix 1 Ä propagate smb_putstatus() failures: the return value is now
    assigned back to i and returned to the caller, so a failed status write is
    no longer silent.

    Fix 2 Ä auto-repair small discrepancies in smb_new_msghdr (rather than hard-failing) when the mismatch is 1-2 records and the .sid length is an
    exact multiple of idxreclen:
    - LONG by 1 (.sid has one orphan record): truncate the extra record with
    chsize() and continue. This was the May 9 failure mode.
    - SHORT by 1-2 (.sid is missing 1-2 records): reduce total_msgs to match
    the actual index length, persist the correction with smb_putstatus(),
    and continue. The orphaned header/data space is harmless and can be
    reclaimed by smbpack.
    - Mismatch of 3+ records, or non-aligned length: still returns
    SMB_ERR_FILE_LEN as before.

    Test cases (smblib/smbidxtest.c, using CuTest framework):
    Test_NoCorruption - baseline: normal add still works
    Test_ShortIndexByOne - .sid truncated by 1 record: auto-repairs
    Test_ShortIndexByTwo - .sid truncated by 2 records: auto-repairs
    Test_LongIndexByOne - .sid extended by 1 record: truncates and proceeds
    Test_LargeCorruptionFails - .sid truncated by 3 records: still returns -206

    All 5 tests pass with the fix; 3 of 5 fail against the original code.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Rob Swindell (on Debian Linux)@VERT to Git commit to main/sbbs/master on Sat Jul 4 18:24:37 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/7b48c6a6bb234217b80c2695
    Modified Files:
    src/smblib/smblib.c
    Log Message:
    Prevent votes/polls from corrupting hyper-allocated message bases

    smb_addmsg() has always forced hyper-allocated storage when the base's status.attr has SMB_HYPERALLOC set, but smb_addvote(), smb_addpoll() and smb_addpollclosure() passed the caller's storage mode (typically derived
    from the sub's configured storage setting via smb_storage_mode()) straight through to smb_addmsghdr(). On a message base whose header file carries
    the SMB_HYPERALLOC attribute while the sub is configured for fast or
    self-pack allocation, a vote/poll header was then allocated via
    smb_fallochdr() or smb_allochdr() against allocation files that hyper-allocation deliberately does not maintain, yielding an offset inside existing headers: the new header overwrote a live message header and
    (spanning two blocks) overran the following one, destroying two messages
    per vote and leaving the base unreadable (smb_getmsghdr "corrupt message
    header ID" errors; chksmb "Duplicate Index Offsets" and "Overlapping
    Headers").

    Guard the header-storage branch in smb_new_msghdr() instead: if the base's persisted attr says hyper-allocated, force SMB_HYPERALLOC storage no
    matter what the caller passed. This protects every header-adding path, including any direct smb_addmsghdr() caller.

    Observed in the wild on the DEBATE sub of Vertrauen (its msgs.ini config selects fast allocation, but the 26-year-old base file is branded SMB_HYPERALLOC): the first votes cast on it destroyed messages #16-#19.

    Fixes issue #1181

    Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
  • From Rob Swindell (on Debian Linux)@VERT to Git commit to main/sbbs/master on Thu Nov 19 09:20:50 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/ce3494e738760fd80e4c44f0
    Modified Files:
    src/smblib/smblib.c
    Log Message:
    smblib: free text_subtype/text_charset in smb_freemsghdrmem()

    smb_freemsghdrmem() ended with clear_convenience_ptrs(), which NULLs text_subtype and text_charset along with the pointers into header-field
    data. Those two are not such pointers: smb_parse_content_type() strdup()s
    them from a text/* Content-Type field, so they leaked each time a header
    with one was freed this way. MsgBase.put_msg_header() does that on every
    call (it re-reads the header and frees its fields before re-parsing the
    JS header object), leaking both strings per call; valgrind flagged it in
    the jsexec-testsuite-valgrind CI jobs.

    Free them alongside the header fields they are derived from.
    smb_freemsgmem() calls smb_freemsghdrmem(), so its own frees of the two
    are dropped.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
  • From Rob Swindell (on Debian Linux)@VERT to Git commit to main/sbbs/master on Sun Nov 22 12:19:51 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/3980634758b2757f7645fb67
    Modified Files:
    src/smblib/smblib.c
    Log Message:
    smblib: smb_copymsgmem() leaves nothing allocated when it fails

    On a failed malloc(), smb_copymsgmem() returned with whatever it had
    already allocated for the copy still in it (leaked by callers that do not
    free the copy), and with the copy's dfield, hfield and hfield_dat still pointing at the source message's arrays wherever it had not replaced
    them yet. A caller that frees both after a failure, as MsgBase.copy_msg()
    and move_msg() do, then freed the source's arrays twice, and one that
    freed the copy after a failure part-way through the header fields freed
    the uninitialized entries of hfield_dat.

    The copy now starts with no arrays of its own, allocates hfield_dat
    zeroed, and on any failure frees what it allocated, leaving the copy
    holding no allocations, so smb_freemsgmem() on it is safe and not freeing
    it leaks nothing.

    Coverity CIDs 662423, 662427, 662429 (bulkmail.cpp).

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
  • From Rob Swindell (on Debian Linux)@VERT to Git commit to main/sbbs/master on Mon Nov 30 01:12:30 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/49ebc4be491f45e2b4b35e6d
    Modified Files:
    src/smblib/smblib.c
    Log Message:
    smblib: retry a message index read that hit EOF under the header lock

    smb_getmsgidx() searches the index (.sid) without a lock, taking the
    file length once at the start. delmail() rewrites the mail base index
    in place and then truncates it, under the header lock since
    d91796ec3a (lift-11-detected, 2026-11-14). A lookup that overlaps the
    nightly e-mail purge can read past the new end-of-file and fail with SMB_ERR_READ (-203), logged by the Mail Server as e.g.:

    !SEND ERROR -203 (smb_getmsgidx reading index at offset 9456
    (byte 189120)) getting message index #758605

    The race predates v3.21: delmail() has rewritten and then truncated the
    index this way since e29085cbff (roots-7-dumb, 2018-04-30).

    On SMB_ERR_READ or SMB_ERR_HDR_OFFSET, take the header lock (if the
    caller doesn't already hold it), discard the stdio read buffer, and
    look up the message once more. A failure that persists is returned as
    before. Lookups that succeed, or that find no such message, take no
    lock, so their cost is unchanged.

    Not addressed: while the index is being compacted it is briefly
    unsorted, so a lookup can also report SMB_ERR_NOT_FOUND (-110) for a
    message that still exists. Retrying that under the lock too would
    make every lookup of a nonexistent message number take the lock.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net
  • From Rob Swindell (on Debian Linux)@VERT to Git commit to main/sbbs/master on Mon Nov 30 22:07:46 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/88691631ab86d4e5529d02f2
    Modified Files:
    src/smblib/smblib.c
    Log Message:
    smblib: don't retry index lookups past the end of the index

    49ebc4be49 (solo-11-sound, 2026-11-30) retried smb_getmsgidx() under the
    header lock on SMB_ERR_HDR_OFFSET as well as SMB_ERR_READ. getmsgidx()
    returns SMB_ERR_HDR_OFFSET only for a lookup by offset at or past the
    index length it read at the start, which a concurrent truncation can only
    make more correct, so the retry never helped. It did cost: every loop
    reading the index by offset until a lookup fails (smb_count_idx_records(),
    JS MsgBase.get_msg_index() by offset) ended by taking the header lock,
    waiting up to retry_time if another process held it.

    A truncation that races a lookup shows up as SMB_ERR_READ, which is still retried.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---
    ■ Synchronet ■ Vertrauen ■ Home of Synchronet ■ [vert/cvs/bbs].synchro.net