The C apps and cgroups lookup clients encoded each request into
send_buf, which SHM framing rewrites in place and a reconnect may
resize. A lookup that reconnected inside the call (a server restart,
or a response over the server's limit) resent the framed bytes, so the
server rejected it, or read the request through a pointer the
reconnect had freed.
Encode lookup requests into a separate request_buf, as the Rust and Go
clients already do; send_buf only holds the SHM frame. Add N12
robustness tests on POSIX and Windows and run test_robustness under
ASAN. SOW-0073; SOW-0074 tracks a test_uds link failure on 64-bit
glibc 2.41 found during validation.
Problem
The C
APPS_LOOKUPandCGROUPS_LOOKUPclients encoded each request intosend_bufand reused that pointer on retry. SHM framing overwrote the encoded request in place, so a retry could send framed bytes as the payload and getNIPC_ERR_BAD_LAYOUT. If reconnect movedsend_buf, the retry could read freed memory. Both violate the resend contract indocs/level2-typed-api.mdsection 5.A server restart can trigger this when a live client calls through its old session. Overflow recovery can also trigger it when even the
PAYLOAD_EXCEEDEDmarkers cannot fit within the server’s fixed response limit. Rust and Go already keep request and frame storage separate.Change
On POSIX and Windows, C lookups encode into a reusable
request_bufand copy the payload intosend_buffor SHM framing.nipc_client_closefrees both buffers. The lookup allocation tests use the appended*_CLIENT_REQUEST_BUF_REALLOCfault sites.Compatibility
The wire format and C function signatures are unchanged. Two appended internal fields change the size of the public
nipc_client_ctx_tstruct, so C consumers must rebuild against the new header. A short SHM A/B for both lookup types at 16 and 256 items found throughput differences within run-to-run variation.Testing
NIPC_ERR_OVERFLOW.1ff116f, all five cases failed in the recorded plain Linux runs. Linux ASan caught a heap-use-after-free on baseline-to-SHM reconnect. On Windows, the SHM-to-SHM and limit cases failed consistently, while baseline-to-SHM failures depended on whetherreallocmoved the buffer. All five pass with the fix on Linux, Linux under ASan, and Windows.test_udswas excluded because it also fails to link on the base commit on 64-bit glibc 2.41 (SOW-0074).tests/run-sanitizer-asan.shnow includestest_robustness. The seven buildable Linux binaries ran individually with ASan, UBSan, and leak detection and produced no reports. Validation covered Linux and Windows.Summary by cubic
Fixes C
APPS_LOOKUPandCGROUPS_LOOKUPretries resending overwritten or freed request bytes after a reconnect.The lookups encoded each request into
send_buf; SHM framing rewrote it in place, so an in-call retry resent the framed bytes as the payload (server repliedNIPC_ERR_BAD_LAYOUT), and a reconnect that resizedsend_bufleft the retry reading through a freed pointer. Lookups now encode into a newrequest_bufand copy intosend_buffor framing, so the retry resends the exact request, matching the Rust and Go clients. This is hit by a server restart under a live client or by a response that exceeds the server's fixed response limit.nipc_client_ctx_tgains two internal fields, so C consumers must rebuild against the new header; wire format and function signatures are unchanged.test_robustnessnow runs in the ASAN suite.Written for commit 74c870a. Summary will update on new commits.
Summary by CodeRabbit