From 591a5c8f612fead396041b929452c906d2cc1d6b Mon Sep 17 00:00:00 2001 From: qupo1 <123211219+qupo1@users.noreply.github.com> Date: Sun, 17 Nov 2024 13:01:30 +0900 Subject: [PATCH] fix CVE-2024-38428 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original patch author: Tim Rühsen Taken from: https://git.savannah.gnu.org/cgit/wget.git/commit/?id=ed0c7c7e0e8f7298352646b2fd6e06a11e242ace --- src/url.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/url.c b/src/url.c index 5dfb91a23..8be607748 100644 --- a/src/url.c +++ b/src/url.c @@ -41,6 +41,7 @@ as that of the covered work. */ #include "url.h" #include "host.h" /* for is_valid_ipv6_address */ #include "c-strcase.h" +#include "c-ctype.h" #ifdef HAVE_ICONV # include @@ -526,12 +527,39 @@ scheme_leading_string (enum url_scheme scheme) static const char * url_skip_credentials (const char *url) { - /* Look for '@' that comes before terminators, such as '/', '?', - '#', or ';'. */ - const char *p = (const char *)strpbrk (url, "@/?#;"); - if (!p || *p != '@') - return url; - return p + 1; + /* + * This whole file implements https://www.rfc-editor.org/rfc/rfc2396 . + * RFC 2396 is outdated since 2005 and needs a rewrite or a thorough re-visit. + * + * The RFC says + * server = [ [ userinfo "@" ] hostport ] + * userinfo = *( unreserved | escaped | ";" | ":" | "&" | "=" | "+" | "$" | "," ) + * unreserved = alphanum | mark + * mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" + */ + static const char *allowed = "-_.!~*'();:&=+$,"; + + for (const char *p = url; *p; p++) + { + if (c_isalnum(*p)) + continue; + + if (strchr(allowed, *p)) + continue; + + if (*p == '%' && c_isxdigit(p[1]) && c_isxdigit(p[2])) + { + p += 2; + continue; + } + + if (*p == '@') + return p + 1; + + break; + } + + return url; } /* Parse credentials contained in [BEG, END). The region is expected