Skip to content

Commit

Permalink
Rollup merge of rust-lang#46671 - varkor:contrib-2, r=KodrAus
Browse files Browse the repository at this point in the history
Reject superfluous `::` in IPv6 addresses

Fixes rust-lang#46263.
  • Loading branch information
kennytm authored Dec 20, 2017
2 parents c3241b5 + bd1cf04 commit 76e2cc5
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 76e2cc5

Please sign in to comment.