Skip to content

Commit

Permalink
Prevent http://[] from causing panic
Browse files Browse the repository at this point in the history
The code:

```
Url::parse("http://[\n:]")
```

The panic:

```
thread '<main>' panicked at 'index out of bounds: the len is 0 but the index is 0',
/Users/coreyf/.cargo/registry/src/github.com-1ecc6299db9ec823/url-0.2.34/src/host.rs:104
```

Was found using https://github.com/kmcallister/afl.rs 👍
  • Loading branch information
frewsxcv committed May 11, 2015
1 parent bfa167b commit dce2818
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ impl Ipv6Address {
let mut piece_pointer = 0;
let mut compress_pointer = None;
let mut i = 0;

if len == 0 {
return Err(ParseError::InvalidIpv6Address)
}

if input[0] == b':' {
if input[1] != b':' {
return Err(ParseError::InvalidIpv6Address)
Expand Down
3 changes: 3 additions & 0 deletions src/urltestdata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ http://Goo%20\sgoo%7C|.com
# This should fail
http://GOO\u00a0\u3000goo.com

# This should fail
http://[]

# Other types of space (no-break, zero-width, zero-width-no-break) are
# name-prepped away to nothing.
XFAIL http://GOO\u200b\u2060\ufeffgoo.com s:http p:/ h:googoo.com
Expand Down

0 comments on commit dce2818

Please sign in to comment.