open
https://gitlab.synchro.net/main/sbbs/-/work_items/1356
A message base handle that stays open can return stale index and
header data after another handle (same process or another process)
rewrites a record in place.
**Cause.** `smb_open_fp()` (src/smblib/smbfile.c) gives each stream a
64 KB buffer with `setvbuf()`. With glibc, an `fseek()` or `rewind()`
whose target lies inside the current read buffer is satisfied from the
buffer without re-reading the file. These read paths seek and read
without flushing first:
- `MsgBase.get_index()` in src/sbbs3/js_msgbase.cpp: `rewind(sid_fp)`
then `fread`
- `smb_getmsgidx()`: `fseek` on the index
- `smb_getmsghdr()`: `fseek` on the header file
`smb_getstatus()` does `fflush(shd_fp)`, which discards the read
buffer, so the status record is always fresh.
**Reproduced** (Linux, glibc; scratch e-mail base; second handle in
the same process and in a child jsexec, same results). Handle B is
opened and its index read once. Through another handle: message 2 is
flagged deleted (`remove_msg`), message 3's header is rewritten, and a
message is appended. Then, on B, without reopening:
- `get_index()` still shows message 2 with attr 0. A new handle, or B
after close and open, shows the delete flag.
- `get_msg_index(2)` and `get_msg_header(2).attr` are stale when read
before anything has flushed the header stream.
- A header read after `get_index()` is fresh, because `get_index()`
calls `smb_getstatus()`, which flushes the header stream. Call order
therefore hides the problem in many scripts.
- The appended message is seen (it lies past the buffered end).
**What is stale:** in-place rewrites (attribute flags such as deleted,
read or spam; a header rewritten in the same slot) that fall inside
the handle's currently buffered window, up to 64 KB, about 3,276
index records. Appends and the status fields are fresh.
**Who is affected:** any consumer that keeps a base open and reads it
again after another handle changed a record: long-lived script
objects, and server code that holds a base open across operations.
Not verified on Windows or with other C libraries.
**Suggested fix:** `fflush()` the stream before the `rewind`/`fseek`
in those three read paths (as `smb_getstatus()` already does for the
header file), or seek with an unbuffered re-read.
-- *Authored by Claude (Claude Code), on behalf of @rswindell*
--- SBBSecho 3.38-Linux
* Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)