| ... | @@ -34,6 +34,7 @@ pub const Address = extern union { | ... | @@ -34,6 +34,7 @@ pub const Address = extern union { |
| 34 | error.InvalidEnd, | 34 | error.InvalidEnd, |
| 35 | error.InvalidCharacter, | 35 | error.InvalidCharacter, |
| 36 | error.Incomplete, | 36 | error.Incomplete, |
| | 37 | error.NonCanonical, |
| 37 | => {}, | 38 | => {}, |
| 38 | } | 39 | } |
| 39 | | 40 | |
| ... | @@ -55,6 +56,7 @@ pub const Address = extern union { | ... | @@ -55,6 +56,7 @@ pub const Address = extern union { |
| 55 | error.InvalidEnd, | 56 | error.InvalidEnd, |
| 56 | error.InvalidCharacter, | 57 | error.InvalidCharacter, |
| 57 | error.Incomplete, | 58 | error.Incomplete, |
| | 59 | error.NonCanonical, |
| 58 | => {}, | 60 | => {}, |
| 59 | } | 61 | } |
| 60 | | 62 | |
| ... | @@ -204,6 +206,7 @@ pub const Ip4Address = extern struct { | ... | @@ -204,6 +206,7 @@ pub const Ip4Address = extern struct { |
| 204 | var x: u8 = 0; | 206 | var x: u8 = 0; |
| 205 | var index: u8 = 0; | 207 | var index: u8 = 0; |
| 206 | var saw_any_digits = false; | 208 | var saw_any_digits = false; |
| | 209 | var has_zero_prefix = false; |
| 207 | for (buf) |c| { | 210 | for (buf) |c| { |
| 208 | if (c == '.') { | 211 | if (c == '.') { |
| 209 | if (!saw_any_digits) { | 212 | if (!saw_any_digits) { |
| ... | @@ -216,7 +219,13 @@ pub const Ip4Address = extern struct { | ... | @@ -216,7 +219,13 @@ pub const Ip4Address = extern struct { |
| 216 | index += 1; | 219 | index += 1; |
| 217 | x = 0; | 220 | x = 0; |
| 218 | saw_any_digits = false; | 221 | saw_any_digits = false; |
| | 222 | has_zero_prefix = false; |
| 219 | } else if (c >= '0' and c <= '9') { | 223 | } else if (c >= '0' and c <= '9') { |
| | 224 | if (c == '0' and !saw_any_digits) { |
| | 225 | has_zero_prefix = true; |
| | 226 | } else if (has_zero_prefix) { |
| | 227 | return error.NonCanonical; |
| | 228 | } |
| 220 | saw_any_digits = true; | 229 | saw_any_digits = true; |
| 221 | x = try std.math.mul(u8, x, 10); | 230 | x = try std.math.mul(u8, x, 10); |
| 222 | x = try std.math.add(u8, x, c - '0'); | 231 | x = try std.math.add(u8, x, c - '0'); |
| ... | @@ -1149,6 +1158,7 @@ fn linuxLookupNameFromHosts( | ... | @@ -1149,6 +1158,7 @@ fn linuxLookupNameFromHosts( |
| 1149 | error.Incomplete, | 1158 | error.Incomplete, |
| 1150 | error.InvalidIPAddressFormat, | 1159 | error.InvalidIPAddressFormat, |
| 1151 | error.InvalidIpv4Mapping, | 1160 | error.InvalidIpv4Mapping, |
| | 1161 | error.NonCanonical, |
| 1152 | => continue, | 1162 | => continue, |
| 1153 | }; | 1163 | }; |
| 1154 | try addrs.append(LookupAddr{ .addr = addr }); | 1164 | try addrs.append(LookupAddr{ .addr = addr }); |