• src/xpdev/sockwrap.c

    From Rob Swindell (on Windows 11)@1:103/705 to Git commit to main/sbbs/master on Sat May 2 18:58:15 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/9bb6aa39080f6af5c62a2166
    Modified Files:
    src/xpdev/sockwrap.c
    Log Message:
    sockwrap: preserve WSAGetLastError() across socket_strerror()

    On Windows, FormatMessageA() shares its TLS slot with WSAGetLastError(),
    and calls SetLastError(ERROR_INSUFFICIENT_BUFFER) on a too-small buffer. Callers that reference SOCKET_ERRNO and SOCKET_STRERROR in the same printf-style call (e.g. main.cpp:2745, telgate.cpp:433) can therefore
    see a bogus normalized error code (e.g. -9878 from 122-WSABASEERR) when argument-evaluation order puts the SOCKET_STRERROR call first and the underlying message overflows the caller's buffer.

    Snapshot WSAGetLastError() at function entry and restore it before
    returning so the side-effect cannot leak.

    Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
    --- SBBSecho 3.37-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)