authorgravatar for git@l4.pmLuna <git@l4.pm> 2020-04-02 17:34:05-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-02 14:56:06-04:00
log64e55a74de8229f0a1cf5a174746e265d56c16fa
tree759453af9116641cb61bbd505f5f8cf5b4d767db
parent10ea2db5cb37adf248b04e8c8b46cbb97b4bda4e

Add validation for scope ids


1 files changed, 15 insertions(+), 2 deletions(-)

lib/std/net.zig+15-2
...@@ -209,8 +209,17 @@ pub const Address = extern union {...@@ -209,8 +209,17 @@ pub const Address = extern union {
209209
210 for (buf) |c, i| {210 for (buf) |c, i| {
211 if (scope_id) {211 if (scope_id) {
212 scope_id_value[scope_id_index] = c;212 // Handling of percent-encoding should be for an URI library.
213 scope_id_index += 1;213 if ((c >= '0' and c <= '9') or
214 (c >= 'A' and c <= 'Z') or
215 (c >= 'a' and c <= 'z') or
216 (c == '-') or (c == '.') or (c == '_') or (c == '~'))
217 {
218 scope_id_value[scope_id_index] = c;
219 scope_id_index += 1;
220 } else {
221 return error.InvalidCharacter;
222 }
214 } else if (c == ':') {223 } else if (c == ':') {
215 if (!saw_any_digits) {224 if (!saw_any_digits) {
216 if (abbrv) return error.InvalidCharacter; // ':::'225 if (abbrv) return error.InvalidCharacter; // ':::'
...@@ -272,6 +281,10 @@ pub const Address = extern union {...@@ -272,6 +281,10 @@ pub const Address = extern union {
272 return error.Incomplete;281 return error.Incomplete;
273 }282 }
274283
284 if (scope_id and scope_id_index == 0) {
285 return error.Incomplete;
286 }
287
275 var resolved_scope_id: u32 = 0;288 var resolved_scope_id: u32 = 0;
276 if (scope_id_index > 0) {289 if (scope_id_index > 0) {
277 const scope_id_str = scope_id_value[0..scope_id_index];290 const scope_id_str = scope_id_value[0..scope_id_index];