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

Inconsistent handling of trailing dots can lead to panic #8

Closed
jonasbb opened this issue Aug 7, 2017 · 2 comments · Fixed by #9
Closed

Inconsistent handling of trailing dots can lead to panic #8

jonasbb opened this issue Aug 7, 2017 · 2 comments · Fixed by #9

Comments

@jonasbb
Copy link
Contributor

jonasbb commented Aug 7, 2017

// Domain { full: "com", typ: Some(Icann), suffix: Some("com"), registrable: None }
eprintln!("{:?}", list.parse_domain("com").unwrap());
// Domain { full: "localhost", typ: None, suffix: None, registrable: None }
eprintln!("{:?}", list.parse_domain("localhost").unwrap());
// Domain { full: "test.com.", typ: None, suffix: Some("com"), registrable: Some("test.com") }
eprintln!("{:?}", list.parse_domain("test.com.").unwrap());
// Domain { full: "test.localhost.", typ: None, suffix: Some("localhost"), registrable: Some("test.localhost") }
eprintln!("{:?}", list.parse_domain("test.localhost.").unwrap());
// panicked at 'index 2 out of range for slice of length 1'
eprintln!("{:?}", list.parse_domain("com.").unwrap());
// panicked at 'index 2 out of range for slice of length 1'
eprintln!("{:?}", list.parse_domain("localhost.").unwrap());

Notice how the suffix is different for localhost and test.localhost.. I am not sure if this is the same or a different issue.

Stracktrace:

  10: <core::ops::range::Range<usize> as core::slice::SliceIndex<[T]>>::index
             at /checkout/src/libcore/slice/mod.rs:866
  11: <core::ops::range::RangeTo<usize> as core::slice::SliceIndex<[T]>>::index
             at /checkout/src/libcore/slice/mod.rs:912
  12: core::slice::<impl core::ops::index::Index<I> for [T]>::index
             at /checkout/src/libcore/slice/mod.rs:717
  13: <alloc::vec::Vec<T> as core::ops::index::Index<core::ops::range::RangeTo<usize>>>::index
             at /checkout/src/liballoc/vec.rs:1584
  14: publicsuffix::Domain::assemble
             at /cargo/registry/src/github.com-1ecc6299db9ec823/publicsuffix-1.4.0/src/lib.rs:600
  15: publicsuffix::Domain::find_match
             at /cargo/registry/src/github.com-1ecc6299db9ec823/publicsuffix-1.4.0/src/lib.rs:647
  16: publicsuffix::Domain::parse::{{closure}}
             at /cargo/registry/src/github.com-1ecc6299db9ec823/publicsuffix-1.4.0/src/lib.rs:677
  17: <core::result::Result<T, E>>::and_then
             at /checkout/src/libcore/result.rs:602
  18: publicsuffix::Domain::parse
             at /cargo/registry/src/github.com-1ecc6299db9ec823/publicsuffix-1.4.0/src/lib.rs:676
  19: publicsuffix::List::parse_dns_name
             at /cargo/registry/src/github.com-1ecc6299db9ec823/publicsuffix-1.4.0/src/lib.rs:484

Changing lib.rs:671 to

        let input = domain.trim_right_matches('.');

fixes the problem. I will provide a pull request with matching tests later.

@rushmorem
Copy link
Owner

Thank you for reporting! Will be looking forward to the pull request.

@rushmorem
Copy link
Owner

Changing lib.rs:671 to

       let input = domain.trim_right_matches('.');

fixes the problem.

Since a valid domain name can only have one trailing ., we must make sure this is the case before calling trim_right_matches otherwise a domain like test.com.. will be parsed as a valid domain name.

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

Successfully merging a pull request may close this issue.

2 participants