fix: use comma-ok type assertion and length guard in parseNtpTimestamp#1590
Open
Aprazor wants to merge 2 commits intoprometheus:mainfrom
Open
fix: use comma-ok type assertion and length guard in parseNtpTimestamp#1590Aprazor wants to merge 2 commits intoprometheus:mainfrom
Aprazor wants to merge 2 commits intoprometheus:mainfrom
Conversation
The bare type assertion pdu.Value.([]byte) panics if the PDU value is not []byte. The subsequent data[:4] and data[4:] slicing panics if data is shorter than 8 bytes. Add proper type check and length validation with descriptive error messages. Signed-off-by: Aprazors <Aprazors@gmail.com>
69c942c to
7465db7
Compare
Per reviewer feedback, add test cases for: - invalid type (integer instead of []byte) - too-short data (less than 8 bytes) Both cases verify the error is returned instead of panicking. Signed-off-by: Aprazors <Aprazors@gmail.com>
Contributor
Author
|
added test cases for the invalid type and too-short data paths. should be good now. |
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.
The bare type assertion pdu.Value.([]byte) panics if the PDU value
is not []byte. The subsequent data[:4] and data[4:] slicing panics
if data is shorter than 8 bytes. Add proper type check and length
validation with descriptive error messages.