fix(protocol): guard acl list reply encode and clamp admin reply counts - #162
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add the missing termination guard to the ACL list reply encoder, and clamp the entry count the admin ports return before the copy loops.
Why
Audit findings AGT-4 and HUB-minor(clamp). Both are latent contract holes, not live exploits — current callers and the SQLite adapter behave.
AdminAclListReplyMessage_Encodestrlen+memcpywithout checking termination first; an unterminatedagent_namerunsstrlenpast the field and writes past the 212-byte slot, overflowing the hub's 4 KiB encode bufferhandleAdminAclList/handleAdminPinsuint8_ta port returns is used directly as the copy-loop bound; a port reporting more than it filled reads past the local array and writes past the reply struct (stack corruption)How
The guard mirrors the five sibling reply encoders (peers, pins, agents, clients, interfaces), checking the three fields this entry carries and returning 0. The clamp is a guard clause at both call sites: the port was handed a buffer of exactly
ADMIN_*_ENTRIES_MAX, so anything beyond that is stack the port never wrote. Boy-scout while in the file: the ACL entry was the only one inlining its field copies, so it now haswriteAclEntry/readAclEntrylike its siblings.Testing
make testgreen (407 tests)test_broker(signal 139) — the overflow is real, not theoreticalNotes
No wire-format change. Broker tests drive a test-local port that fills
max_entriesand reports 255, so the shared mocks stay honest.