-
Notifications
You must be signed in to change notification settings - Fork 72
fix: preserve supported questions when unknown types are present #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Twister915
wants to merge
1
commit into
keepsimple1:main
Choose a base branch
from
Twister915:fix/parse-mixed-questions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+65
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2331,9 +2331,11 @@ impl DnsIncoming { | |||||||||||||||
| self.offset += 4; | ||||||||||||||||
|
|
||||||||||||||||
| let Some(rr_type) = RRType::from_u16(ty) else { | ||||||||||||||||
| return Err(Error::Msg(format!( | ||||||||||||||||
| "DNS incoming: question idx {i} qtype unknown: {ty}", | ||||||||||||||||
| ))); | ||||||||||||||||
| // The name, type and class have already been consumed. An | ||||||||||||||||
| // unsupported question must not discard supported questions or | ||||||||||||||||
| // resource records elsewhere in this packet. | ||||||||||||||||
| trace!("DNS incoming: skipping question idx {i} qtype unknown: {ty}"); | ||||||||||||||||
| continue; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| self.questions.push(DnsQuestion { | ||||||||||||||||
|
|
@@ -3360,6 +3362,66 @@ mod tests { | |||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn test_unknown_questions_preserve_supported_questions_and_answers() { | ||||||||||||||||
| // No enum variant is needed for future question types. Build the wire | ||||||||||||||||
| // questions explicitly so this also covers types the writer cannot emit. | ||||||||||||||||
| for unknown_type in [64u16, 65, 65400] { | ||||||||||||||||
| for unknown_index in 0..3 { | ||||||||||||||||
| let mut data = vec![0; 12]; | ||||||||||||||||
| data[4..6].copy_from_slice(&3u16.to_be_bytes()); | ||||||||||||||||
| data[6..8].copy_from_slice(&1u16.to_be_bytes()); | ||||||||||||||||
| let mut known_types = [1u16, 28].iter().copied(); | ||||||||||||||||
| for index in 0..3 { | ||||||||||||||||
| data.extend_from_slice(b"\x05mixed\x05local\x00"); | ||||||||||||||||
| let ty = if index == unknown_index { | ||||||||||||||||
| unknown_type | ||||||||||||||||
| } else { | ||||||||||||||||
| known_types.next().unwrap() | ||||||||||||||||
| }; | ||||||||||||||||
| data.extend_from_slice(&ty.to_be_bytes()); | ||||||||||||||||
| data.extend_from_slice(&CLASS_IN.to_be_bytes()); | ||||||||||||||||
| } | ||||||||||||||||
| // One known answer after the questions verifies parser alignment. | ||||||||||||||||
| data.extend_from_slice( | ||||||||||||||||
| b"\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x78\x00\x04\xc0\x00\x02\x01", | ||||||||||||||||
| ); | ||||||||||||||||
| let incoming = DnsIncoming::new(data, test_interface_id()).unwrap(); | ||||||||||||||||
| let types: Vec<_> = incoming | ||||||||||||||||
| .questions() | ||||||||||||||||
| .iter() | ||||||||||||||||
| .map(|q| q.entry.ty) | ||||||||||||||||
| .filter(|ty| matches!(ty, RRType::A | RRType::AAAA)) | ||||||||||||||||
| .collect(); | ||||||||||||||||
| assert_eq!(types, [RRType::A, RRType::AAAA]); | ||||||||||||||||
| if unknown_type == 65400 { | ||||||||||||||||
| assert_eq!(incoming.questions().len(), 2); | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+3397
to
+3399
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| assert_eq!(incoming.answers().len(), 1); | ||||||||||||||||
| assert_eq!(incoming.answers()[0].get_type(), RRType::A); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn test_unknown_question_still_requires_complete_name_type_and_class() { | ||||||||||||||||
| let mut data = vec![0; 12]; | ||||||||||||||||
| data[4..6].copy_from_slice(&1u16.to_be_bytes()); | ||||||||||||||||
| data.extend_from_slice(b"\x05mixed\x05local\x00"); | ||||||||||||||||
| data.extend_from_slice(&65400u16.to_be_bytes()); | ||||||||||||||||
| data.extend_from_slice(&CLASS_IN.to_be_bytes()); | ||||||||||||||||
| assert!(DnsIncoming::new(data.clone(), test_interface_id()) | ||||||||||||||||
| .unwrap() | ||||||||||||||||
| .questions() | ||||||||||||||||
| .is_empty()); | ||||||||||||||||
| for missing in 1..=4 { | ||||||||||||||||
| assert!( | ||||||||||||||||
| DnsIncoming::new(data[..data.len() - missing].to_vec(), test_interface_id()) | ||||||||||||||||
| .is_err() | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| fn test_interface_id() -> InterfaceId { | ||||||||||||||||
| InterfaceId { | ||||||||||||||||
| name: "test".to_string(), | ||||||||||||||||
|
|
||||||||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed with your comments in the Description, I think
debug!is probably better here.