BBS:      TELESC.NET.BR
Assunto:  src/smblib/smblib.c
De:       Rob Swindell (on Debian Linux)
Data:     Mon, 11 May 2026 23:57:27 -0700
-----------------------------------------------------------
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.
n
---
  mSynchronetn  hgVertrauen n hHome of Synchronet n gh[vert/cvs/bbs].synchro.net

-----------------------------------------------------------
[Voltar]