• src/smblib/smballoc.c smblib.c src/smblib/tests/smballoctest.c

    From Rob Swindell (on Windows 11)@VERT to Git commit to main/sbbs/master on Sat Nov 14 11:52:09 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/eb01f9eed5d49a34d1bc76f2
    Modified Files:
    src/smblib/smballoc.c smblib.c src/smblib/tests/smballoctest.c
    Log Message:
    smblib: don't misallocate or truncate on a bad allocation file or read

    Hazards in the allocation code that could overwrite or discard live
    message headers or text:

    - smb_allocdat() and smb_allochdr() treated a read error during the
    scan for free blocks as the end of the allocation file, and so
    allocated the new message at that point, on top of blocks in use.
    A read error now fails the allocation. The scan loops predate the
    2004 split of smblib.c.

    - smb_freemsghdr() truncated the header file at the header being freed
    whenever the header allocation file was not longer than that header's
    end. A short or empty .sha (a missing one is created empty on open)
    or a failed length query therefore discarded every later header. It
    now truncates only when the header is exactly the last one accounted
    for, and fails when the header lies beyond the allocation file.

    - smb_freemsgdat() truncated the data file to the length implied by
    the data allocation file. A failed length query yielded -1, which
    divided to 0 and passed the ">= 0" check, truncating the data file to
    nothing; a short .sda truncated text the same way. It now truncates
    only the blocks it just removed from the end of the allocation file,
    and only when the data file was no longer than that file accounted
    for.

    - smb_freemsgdat() left the .sda open, exclusively, on two early
    returns when it had opened the file itself.

    - smb_new_msghdr(), when moving an existing header that has outgrown
    its blocks, unlocked a header lock held by its caller, so
    smb_updatemsg() completed its index write unlocked. It now leaves a
    caller-held lock in place in that case; smb_addmsghdr() still always
    unlocks.

    The truncation logic dates from 23523b22dfe (2017-11-16) and the
    header-growth path from b18b0f6590c (2023-05-07).

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

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