diff --git a/lib/std/net.zig b/lib/std/net.zig index 9c7d8f2854..96442b9933 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -209,8 +209,17 @@ pub const Address = extern union { for (buf) |c, i| { if (scope_id) { - scope_id_value[scope_id_index] = c; - scope_id_index += 1; + // Handling of percent-encoding should be for an URI library. + if ((c >= '0' and c <= '9') or + (c >= 'A' and c <= 'Z') or + (c >= 'a' and c <= 'z') or + (c == '-') or (c == '.') or (c == '_') or (c == '~')) + { + scope_id_value[scope_id_index] = c; + scope_id_index += 1; + } else { + return error.InvalidCharacter; + } } else if (c == ':') { if (!saw_any_digits) { if (abbrv) return error.InvalidCharacter; // ':::' @@ -272,6 +281,10 @@ pub const Address = extern union { return error.Incomplete; } + if (scope_id and scope_id_index == 0) { + return error.Incomplete; + } + var resolved_scope_id: u32 = 0; if (scope_id_index > 0) { const scope_id_str = scope_id_value[0..scope_id_index];