Reject superfluous :: in IPv6 addresses

Fixes #46263.
This commit is contained in:
varkor 2017-12-11 23:02:14 +00:00
parent ddbb27a241
commit bd1cf04ca7
2 changed files with 6 additions and 1 deletions

View File

@ -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]

View File

@ -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]))
}