Repository navigation
Validate JSON object types in Consul responses - #3584
Merged
Merged
Conversation
Check that each node and its Service value are JSON objects before using object accessors. Skip invalid entries while retaining valid services and reject responses containing only invalid entries. Add HTTP client/server regression coverage for non-object values at both boundaries, mixed valid and invalid entries, and stale result clearing.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The validation is correct, preserves existing behavior, and has focused regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Adds robust JSON type validation to Consul service discovery.
Changes:
- Skips non-object response entries and
Servicevalues. - Adds regression tests for invalid, mixed, and stale responses.
| File | Description |
|---|---|
src/brpc/policy/consul_naming_service.cpp |
Validates JSON objects before member access. |
test/brpc_naming_service_unittest.cpp |
Covers malformed Consul response values. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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 problem does this PR solve?
Issue Number: N/A
Problem Summary:
The Consul naming service assumes that every response array entry and its
Servicefield are JSON objects before accessing their members. Responsescontaining other JSON value types are not handled correctly.
What is changed and the side effects?
Changed:
IsObject()before accessing object members andskip invalid entries using the existing error-handling policy.
boundaries, mixed valid and invalid entries, and stale result clearing.
The test server uses an automatically assigned port.
Side effects:
responses retain valid services; responses with only invalid entries are
rejected.
Check List: