Add validation for scope ids

master
Luna 2020-04-02 17:34:05 -03:00 committed by Andrew Kelley
parent 10ea2db5cb
commit 64e55a74de
1 changed files with 15 additions and 2 deletions

View File

@ -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];