Log an error when a PCRE-HOST-PATTERN is used with FEATURE_PCRE_HOST_PATTERNS disabled
authorFabian Keil <fk@fabiankeil.de>
Sat, 12 Dec 2020 10:45:32 +0000 (11:45 +0100)
committerFabian Keil <fk@fabiankeil.de>
Mon, 14 Dec 2020 07:49:16 +0000 (08:49 +0100)
Don't treat this a fatal error so the regression tests
can be used with and without FEATURE_PCRE_HOST_PATTERNS.

urlmatch.c

index 23a6b54..3cd1147 100644 (file)
@@ -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, '/');