Skip to content

Improve rpc msg handling#459

Merged
carlgsmith merged 3 commits into
alliedtelesis:masterfrom
sparlane:improve_rpc_msg_handling
Jun 5, 2026
Merged

Improve rpc msg handling#459
carlgsmith merged 3 commits into
alliedtelesis:masterfrom
sparlane:improve_rpc_msg_handling

Conversation

@sparlane

@sparlane sparlane commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Handle some edge cases in the rpc message processing

sparlane and others added 3 commits June 5, 2026 18:30
rpc_msg_decode_string() only checked that the read offset was within the
message before calling strlen() on the bytes there. The receive buffer is
sized to the number of bytes received and is not guaranteed to be NUL
padded, so a message whose final string is not NUL terminated caused
strlen() to read past the end of the heap allocation (out-of-bounds read).
Apteryx accepts messages over TCP as well as unix sockets, so this is
reachable from untrusted peers.

Require the string to be NUL terminated within the remaining message bytes
(memchr); otherwise treat the message as malformed and return NULL.

Adds a test that decodes an unterminated buffer sized past the minimum
allocation - this reliably trips AddressSanitizer without the bound.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
When decoding a tree, an rpc_value marker not followed by a key string
left key == NULL, which was then passed to g_strdup()/strrchr() and
dereferenced - a single truncated message (e.g. one trailing rpc_value
byte) crashed the daemon while decoding a SET/QUERY. As this is reachable
from any peer it is a denial of service.

Treat a missing key as end-of-input and return what has been decoded so
far. Adds a test decoding a lone rpc_value marker.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
_rpc_msg_decode_tree() recursed once per rpc_start_children marker with no
limit, so a small message consisting of many nested markers could exhaust
the stack and crash the daemon - a denial of service reachable from any
peer.

Thread a depth counter through the recursion and stop at
RPC_MSG_MAX_TREE_DEPTH (1024), far beyond any real configuration tree.
Decoding then unwinds and returns the partial tree instead of overflowing.

Adds a test that decodes a message of 200k nesting markers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@carlgsmith
carlgsmith merged commit 19e2895 into alliedtelesis:master Jun 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants