From: Fabian Keil <fk@fabiankeil.de>
Date: Sat, 12 Dec 2020 10:45:32 +0000 (+0100)
Subject: Log an error when a PCRE-HOST-PATTERN is used with FEATURE_PCRE_HOST_PATTERNS disabled
X-Git-Tag: v_3_0_30~270^2~31
X-Git-Url: http://www.privoxy.org/gitweb/%22https:/@default-cgi@/user-manual/faq/static/documentation.html?a=commitdiff_plain;h=1a04091dfb254e1b89a107d27cccb4c55c565f51;p=privoxy.git

Log an error when a PCRE-HOST-PATTERN is used with FEATURE_PCRE_HOST_PATTERNS disabled

Don't treat this a fatal error so the regression tests
can be used with and without FEATURE_PCRE_HOST_PATTERNS.
---

diff --git a/urlmatch.c b/urlmatch.c
index 23a6b543..3cd1147c 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -704,9 +704,9 @@ static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchorin
 static jb_err compile_url_pattern(struct pattern_spec *url, char *buf)
 {
    char *p;
+   const size_t prefix_length = 18;
 
 #ifdef FEATURE_PCRE_HOST_PATTERNS
-   const size_t prefix_length = 18;
    if (strncmpic(buf, "PCRE-HOST-PATTERN:", prefix_length) == 0)
    {
       url->pattern.url_spec.host_regex_type = PCRE_HOST_PATTERN;
@@ -717,6 +717,22 @@ static jb_err compile_url_pattern(struct pattern_spec *url, char *buf)
    {
       url->pattern.url_spec.host_regex_type = VANILLA_HOST_PATTERN;
    }
+#else
+   if (strncmpic(buf, "PCRE-HOST-PATTERN:", prefix_length) == 0)
+   {
+      log_error(LOG_LEVEL_ERROR,
+         "PCRE-HOST-PATTERN detected while Privoxy has been compiled "
+         "without FEATURE_PCRE_HOST_PATTERNS: %s",
+         buf);
+      /* Overwrite the "PCRE-HOST-PATTERN:" prefix */
+      memmove(buf, buf+prefix_length, strlen(buf+prefix_length)+1);
+      /*
+       * The pattern will probably not work as expected.
+       * We don't simply return JB_ERR_PARSE here so the
+       * regression tests can be loaded with and without
+       * FEATURE_PCRE_HOST_PATTERNS.
+       */
+   }
 #endif
 
    p = strchr(buf, '/');