Skip to content

Commit

Permalink
Reject superfluous :: in IPv6 addresses
Browse files Browse the repository at this point in the history
Fixes #46263.
  • Loading branch information
varkor committed Dec 11, 2017
1 parent ddbb27a commit bd1cf04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/libstd/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,9 @@ mod tests {
// two double colons
let none: Option<Ipv6Addr> = "1:2::6::8".parse().ok();
assert_eq!(None, none);
// `::` indicating zero groups of zeros
let none: Option<Ipv6Addr> = "1:2:3:4::5:6:7:8".parse().ok();
assert_eq!(None, none);
}

#[test]
Expand Down
4 changes: 3 additions & 1 deletion src/libstd/net/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ impl<'a> Parser<'a> {
}

let mut tail = [0; 8];
let (tail_size, _) = read_groups(self, &mut tail, 8 - head_size);
// `::` indicates one or more groups of 16 bits of zeros
let limit = 8 - (head_size + 1);
let (tail_size, _) = read_groups(self, &mut tail, limit);
Some(ipv6_addr_from_head_tail(&head[..head_size], &tail[..tail_size]))
}

Expand Down

0 comments on commit bd1cf04

Please sign in to comment.