mirror of
https://github.com/VibeDarling/darlingserver.git
synced 2026-11-15 10:18:05 -10:00
For a reply that carries descriptors, the generated client wrapper
counts the non-negative descriptor fields in the reply body, checks that
the message carries exactly that many descriptors, and then uses each
body field as an index into its local fds[] array. The body is read from
the socket and the field is never compared with the number of
descriptors received, so a reply with an index the message does not back
reads past the end of fds[] (a stack array sized for the largest
descriptor count of the call) and hands that value back as a descriptor,
or closes it.
Check each such index against valid_fd_count right after the descriptors
are copied. On an out-of-range index close the received descriptors and
return the existing bad-message status, as for the neighbouring
malformed-control-message check. The change is in the template
(scripts/generate-rpc-wrappers.py), so every generated wrapper that
returns descriptors gets it: the generated rpc.c grows by 42 lines for 6
functions, the generated headers are unchanged.
Rung 2 (this tree); no Apple behaviour involved.
Verification (host only; darlingserver and the Darling client were not
built):
tests/run-rpc-reply-fd.sh
runs the real generator, compiles the generated rpc.c against
socket-backed hooks and drives dserver_rpc_console_open() through a
socketpair with crafted replies (index 0 of 1, index -1, indices 1,
2, 1000000 and 2147483647 with one descriptor attached).
with the change: 15 of 15 checks pass (SANITIZE=undefined and with
no sanitizer).
on origin/main (9abef82): UBSan reports "index 1 out of bounds for
type 'int [1]'"; without sanitizers the test segfaults.
Mutation, scratch copy of the generator: ">" instead of ">=" fails 3
checks, dropping the close of the received descriptors fails 4.