• src/sbbs3/smbutil.c src/s

    From Rob Swindell (on Windows@VERT to Git commit to main/sbbs/m on Sat Nov 14 11:52:00 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/01169480cc48191191a13829
    Modified Files:
    src/sbbs3/smbutil.c src/smblib/smballoc.c smbfile.c src/smblib/tests/smballoctest.c
    Log Message:
    smblib: keep a caller-held header lock in smb_freemsgdat() and friends

    smb_freemsgdat() (and so smb_freemsg_dfields() and smb_freemsg()) and smb_incmsg_dfields() unlocked the message base header on return even
    when the caller had locked it. A caller that locks the header, frees or references message data, and then rewrites the index from a copy it
    read earlier therefore did the rewrite unlocked: a message or file
    added by another process in between lost its index record, and the
    status record (last message number, total) was written back stale.

    Callers affected: smbutil's maintenance (which lost the lock at the
    first message it freed and held no lock file either), fixsmb,
    delusermail(), and smb_removefile().

    These functions now unlock the header only when they locked it. Every
    caller either unlocks explicitly afterward or calls with the header
    unlocked, so none depended on the implicit unlock. Maintenance of a
    large base now holds the header lock for its whole duration, so a
    concurrent post waits (and can time out) instead of being dropped from
    the index.

    The unconditional unlock dates from 874e8bcdbc (2017-11-21).

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
  • From Rob Swindell (on Debian L@VERT to Git commit to main/sbbs/m on Sat Nov 14 13:59:00 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/68762da2e1bcee1f93335059
    Modified Files:
    src/sbbs3/smbutil.c src/smblib/smballoc.c src/smblib/tests/smballoctest.c
    Log Message:
    smblib: don't allocate over data or headers the allocation file misses

    smb_allocdat() and smb_allochdr() scanned the allocation file for free
    blocks until a read came up short and, when that read set EOF rather
    than an error, took the scan's position as the end of the file. An
    allocation file that read short or empty, as it can over a stalled
    network share, therefore placed the new message at block 0, on top of
    a live message. The same view made smb_fallocdat() and smb_fallochdr()
    append at block 0.

    A mail base was found with exactly this: an error notification written
    by a Windows host during a loopback CIFS stall was allocated data block
    0, already in use, overwriting that message's text; the allocation
    record still counted one reference.

    The scans now read the length of the allocation file first and treat a
    short read before its end as an error. When a new message is appended
    rather than placed in free blocks, it now goes after the end of the
    data (or header) file if that file is longer than its allocation file
    accounts for: blocks past the end of the allocation file are
    unaccounted for, not free. smb_allochdr() also gains the maximum header
    offset check that the other header allocators have.

    smbutil's pack allocates while reading the old data and header files
    through the base's file pointers, so it now points them at the new
    files for the allocation calls; packed output is unchanged.

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