authorgravatar for lacc97@protonmail.chLuis Cáceres <lacc97@protonmail.ch> 2023-08-30 22:39:15+00:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-09-06 11:14:24+03:00
log8976ad7ecbd6a0c70749e3bef9c508d0bfde02d2
tree785a2a299ab568bbd563f7991ca333d9e229cc73
parente980bd0aeedff7841882373b42a036c1c985e28f

std.net: Fix IPv6 address parsing for single digit

This fixes the case where IPv6 address parsing incorrectly succeeded on input such as `1`, which now returns error.Incomplete.

2 files changed, 6 insertions(+), 0 deletions(-)

lib/std/net.zig+3
......@@ -406,6 +406,9 @@ pub const Ip6Address = extern struct {
406406 if (!saw_any_digits and !abbrv) {
407407 return error.Incomplete;
408408 }
409 if (!abbrv and index < 14) {
410 return error.Incomplete;
411 }
409412
410413 if (index == 14) {
411414 ip_slice[14] = @as(u8, @truncate(x >> 8));
lib/std/net/test.zig+3
......@@ -13,6 +13,7 @@ test "parse and render IPv6 addresses" {
1313 "FF01::Fb",
1414 "::1",
1515 "::",
16 "1::",
1617 "2001:db8::",
1718 "::1234:5678",
1819 "2001:db8::1234:5678",
......@@ -24,6 +25,7 @@ test "parse and render IPv6 addresses" {
2425 "ff01::fb",
2526 "::1",
2627 "::",
28 "1::",
2729 "2001:db8::",
2830 "::1234:5678",
2931 "2001:db8::1234:5678",
......@@ -48,6 +50,7 @@ test "parse and render IPv6 addresses" {
4850 try testing.expectError(error.InvalidEnd, net.Address.parseIp6("FF01:0:0:0:0:0:0:FB:", 0));
4951 try testing.expectError(error.Incomplete, net.Address.parseIp6("FF01:", 0));
5052 try testing.expectError(error.InvalidIpv4Mapping, net.Address.parseIp6("::123.123.123.123", 0));
53 try testing.expectError(error.Incomplete, net.Address.parseIp6("1", 0));
5154 // TODO Make this test pass on other operating systems.
5255 if (builtin.os.tag == .linux or comptime builtin.os.tag.isDarwin()) {
5356 try testing.expectError(error.Incomplete, net.Address.resolveIp6("ff01::fb%", 0));