Skip to content

Commit bd1cf04

Browse files
committed
Reject superfluous :: in IPv6 addresses
Fixes #46263.
1 parent ddbb27a commit bd1cf04

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/libstd/net/ip.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,9 @@ mod tests {
14511451
// two double colons
14521452
let none: Option<Ipv6Addr> = "1:2::6::8".parse().ok();
14531453
assert_eq!(None, none);
1454+
// `::` indicating zero groups of zeros
1455+
let none: Option<Ipv6Addr> = "1:2:3:4::5:6:7:8".parse().ok();
1456+
assert_eq!(None, none);
14541457
}
14551458

14561459
#[test]

src/libstd/net/parser.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ impl<'a> Parser<'a> {
246246
}
247247

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

0 commit comments

Comments
 (0)