Skip to content
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

Zone parses time/TTL string (parse_time) panic when parsing a too long TTL string. #1963

Closed
kynehc opened this issue Jun 9, 2023 · 1 comment · Fixed by #1964
Closed

Comments

@kynehc
Copy link

kynehc commented Jun 9, 2023

Describe the bug
Zone parses time/TTL string (parse_time) panic when parsing a too long TTL string like "7102w", instead of resulting in an Err.

To Reproduce

use trust_dns_proto::serialize::txt::Parser;
    
assert_eq!(Parser::parse_time("7102w").unwrap(), 0);

or feed a zone file

#[test]
fn test_zone_parse() {
        let domain = Name::from_str("parameter.origin.org.").unwrap();

        let zone_data = r#"$ORIGIN origin.org.
@	IN	SOA	dns1.origin.org.	hostmaster.origin.org. (
			1 
			6h 
			1h 
			7102w 
			1d ) 
		     
		           
	IN	NS	dns1.origin.org.       
	IN	NS	dns2.origin.org.        
	
	
	IN	MX	10	mail.origin.org.       
	IN	MX	20	mail2.origin.org.        

	
dns1	IN	A	10.0.1.1
dns2	IN	A	10.0.1.2	
"#;

        let lexer = Lexer::new(zone_data);
        let result = Parser::new().parse(lexer, Some(domain));

Expected behavior
When parsing an invalid zone, we expected an Err, but instead trust-dns panics:

thread 'main' panicked at 'attempt to multiply with overflow', crates/proto/src/serialize/txt/zone.rs:435:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

System:

  • OS: macOS
  • Architecture: intel x64
  • Version: main
  • rustc version: 1.69.0

Version:
Crate: client
Version: main

Additional context

The problem is due to a potential arithmetic overflow in parse_time(). https://github.com/bluejekyll/trust-dns/blob/d3e822246859ab0aaa92cd2a7eeeb79e60891e00/crates/proto/src/serialize/txt/zone.rs#LL412-L435

@djc
Copy link
Collaborator

djc commented Jun 9, 2023

@kynehc thanks for the report, please have a look at #1964.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants