From: Fabian Keil <fk@fabiankeil.de> Date: Sun, 27 Aug 2023 12:26:02 +0200 Origin: upstream, https://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff;h=87253c99, https://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff;h=e73b93ea Forwarded: not-needed Bug: https://sourceforge.net/p/ijbswa/bugs/935/#4755 Subject: pcre2 compile_pattern(): Pass the anchored pattern to pcre2_compile() Previously the un-anchoring pattern was compiled resulting in incorrect matches. For example requests to: https://www.privoxy.org/user-manual/config.html were redirected because of the default.action section: {+redirect{http://config.privoxy.org/}} # Sticky Actions = +redirect{http://config.privoxy.org/} # URL = http://www.privoxy.org/config # Redirected URL = http://www.privoxy.org/config # Redirect Destination = http://config.privoxy.org/ .privoxy.org/config As the path pattern is left-anchored it should not match. Additionally add a regression test for this. --- a/urlmatch.c +++ b/urlmatch.c @@ -666,7 +666,7 @@ static jb_err compile_pattern(const char snprintf(rebuf, rebuf_size, fmt, pattern); - *regex = pcre2_compile((const unsigned char *)pattern, + *regex = pcre2_compile((const unsigned char *)rebuf, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errcode, &error_offset, NULL); if (*regex == NULL) --- a/regression-tests.action +++ b/regression-tests.action @@ -1152,3 +1152,8 @@ PCRE-HOST-PATTERN:^a{3}\.example\.org$ # Blocked URL = http://bbb.example.org/ # Level = 26 PCRE-HOST-PATTERN:^(bbb|ccc|ddd)\.example\.org$ + +{+block{Block should not apply because the path pattern is left-anchored}} +# Sticky Actions = -block +# URL = http://www.example.org/tralala/blafasel +www.example.org/blafasel