From 2f099e1b14df59f4d40e08cc383a49673c9479d1 Mon Sep 17 00:00:00 2001 From: "Tobias S. Josefowitz" <tobij@tobij.de> Date: Wed, 2 Dec 2020 22:33:24 +0100 Subject: [PATCH] Standards.URI: Never use the input string as string representation Case in scheme, host and so on also can desync the raw input uri from the parsed components. --- lib/modules/Standards.pmod/URI.pike | 32 +++++------------------------ 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/lib/modules/Standards.pmod/URI.pike b/lib/modules/Standards.pmod/URI.pike index ea5176256c..082337db12 100644 --- a/lib/modules/Standards.pmod/URI.pike +++ b/lib/modules/Standards.pmod/URI.pike @@ -49,20 +49,12 @@ string raw_uri; // FIXME: What about decoding of Percent-Encoding (RFC3986 2.1)? // cf pct-encoded in the functions below. -protected enum cache_advice { - DO_NOT_CACHE, - MAY_CACHE, -}; - // Parse authority component (according to RFC 1738, � 3.1) // Updated to RFC 3986 $ 3.2. // NOTE: Censors the userinfo from the @[authority] variable. -protected cache_advice parse_authority() +protected void parse_authority() { string host_port = authority; - int default_port; - cache_advice advice = MAY_CACHE; - // authority = [ userinfo "@" ] host [ ":" port ] if(sscanf(authority, "%[^@]@%s", string userinfo, host_port) == 2) { @@ -71,28 +63,18 @@ protected cache_advice parse_authority() DEBUG("parse_authority(): user=%O, password=%O", user, password); } if(scheme) - default_port = port = Protocols.Ports.tcp[scheme]; // Set a good default � la RFC 1700 + port = Protocols.Ports.tcp[scheme]; // Set a good default � la RFC 1700 // host = IP-literal / IPv4address / reg-name if (has_prefix(host_port, "[")) { // IP-literal = "[" ( IPv6address / IPvFuture ) "]" // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) - if (sscanf(host_port, "[%s]%*[:]%d", host, port) == 3 - && port == default_port) - { - advice = DO_NOT_CACHE; - } + sscanf(host_port, "[%s]%*[:]%d", host, port); } else { // IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet // reg-name = *( unreserved / pct-encoded / sub-delims ) - if (sscanf(host_port, "%[^:]%*[:]%d", host, port) == 3 - && port == default_port) - { - advice = DO_NOT_CACHE; - } + sscanf(host_port, "%[^:]%*[:]%d", host, port); } DEBUG("parse_authority(): host=%O, port=%O", host, port); - - return advice; } // Inherit all properties except raw_uri and base_uri from the URI uri. :-) @@ -325,15 +307,11 @@ void reparse_uri(this_program|string|void base_uri) // scheme is inherited from the base URI's scheme component. if(scheme) { - int do_cache = 1; - if(authority) - do_cache = parse_authority() == MAY_CACHE; + parse_authority(); DEBUG("Scheme found! RFC 2396, �5.2, step 3 " "says we're absolute. Done!"); - if (do_cache) - sprintf_cache['s'] = raw_uri; return; } scheme = this_program::base_uri->scheme; -- GitLab