grpcutil: keep cached endpoints on SRV-target A-record failure (#7730) - #7777
Open
mehrdadbn9 wants to merge 5 commits into
Open
grpcutil: keep cached endpoints on SRV-target A-record failure (#7730)#7777mehrdadbn9 wants to merge 5 commits into
mehrdadbn9 wants to merge 5 commits into
Conversation
added 5 commits
August 16, 2026 03:34
trimStringByBytes scans backwards from the truncation point to find a
UTF-8 rune start, but the loop had no lower bound. When a request field
consists only of UTF-8 continuation bytes (0x80-0xBF) there is no rune
start to land on, so size underflows past zero and bytesStr[-1] panics
with 'index out of range [-1]'. Because the active query tracker is
enabled by default and the panic happens on a goroutine without recover(),
an attacker-supplied match[]/query value can crash the querier.
Bound the scan with 'size > 0' so it stops at the start of the string
instead of underflowing. When no rune start exists the field is truncated
to an empty string, which is safe.
Add TestTrimForJsonMarshalContinuationBytes covering the all-continuation-
byte case; existing multi-byte tests use valid UTF-8 ('世') which always
terminates the scan at index 0 and therefore never exercised the underflow.
Fixes cortexproject#7729
Signed-off-by: ...
Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
…roject#7731) Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
…#7731) Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
…xproject#7730) Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
Contributor
Author
CI note: the
|
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.
Summary
Fixes #7730.
The gRPC DNS watcher (
dnssrv:///dnssrvnoa://) takes the SRV path inlookup(). #7698 madelookup()keep cached endpoints when both the SRVand A-record lookups fail, but the SRV path was still vulnerable: when the
SRV query succeeds but every target's A-record resolution fails transiently,
lookupSRV()returned a non-nil empty map.lookup()then neither fellback to the A-record path nor took the "keep cached" early return, and
proceeded to
compileUpdate(empty), deleting every known endpoint.Solution
lookupSRV()now returnsnil(not an empty map) when SRV records existedbut none of their targets resolved, so
lookup()keeps the previouslycached endpoints — matching the A-record path contract. A genuine
zero-record SRV result (
srvsempty) still returns the empty map and ishandled as before.
Verification
Added
TestDNSWatcher_LookupSRV_TransientTargetFailureRetainsCache, whichstubs the SRV query to return a record whose target A-lookup fails and
asserts
lookup()returnsniland retainscurAddrs. The existingTestDNSWatcher_Lookup_TransientFailureRetainsCache(A-record path) stillpasses.
go test ./pkg/util/grpcutil/ -run TestDNSWatcher -count=1Fixes #7730
Signed-off-by: mehrdadbn9 mehrdadbn9@users.noreply.github.com