From: Fabian Keil <fk@fabiankeil.de>
Date: Sat, 25 Jan 2025 18:11:26 +0000 (+0100)
Subject: compile_pattern(): Use pcre2_get_error_message() to provide better error messages
X-Git-Url: http://www.privoxy.org/gitweb/@default-cgi@/static/faq/@default-cgi@send-stylesheet?a=commitdiff_plain;h=7048c69604ebf29fe79116c1d7c322bebc391150;p=privoxy.git

compile_pattern(): Use pcre2_get_error_message() to provide better error messages
---

diff --git a/urlmatch.c b/urlmatch.c
index 494a69a9..ea433d9a 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -628,6 +628,7 @@ jb_err parse_http_request(const char *req, struct http_request *http)
 static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchoring,
                               struct pattern_spec *url, pcre2_code **regex)
 {
+   PCRE2_UCHAR error_message[120];
    int errcode;
    const char *fmt = NULL;
    char *rebuf;
@@ -671,8 +672,9 @@ static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchorin
       &error_offset, NULL);
    if (*regex == NULL)
    {
-      log_error(LOG_LEVEL_ERROR, "error compiling %s from %s: %s",
-         pattern, url->spec, rebuf);
+      pcre2_get_error_message(errcode, error_message, sizeof(error_message));
+      log_error(LOG_LEVEL_ERROR, "Failed to compile '%s' (%s) from '%s': %s",
+         pattern, rebuf, url->spec, error_message);
       freez(rebuf);
 
       return JB_ERR_PARSE;
@@ -683,9 +685,10 @@ static jb_err compile_pattern(const char *pattern, enum regex_anchoring anchorin
    if ((ret = pcre2_jit_compile(*regex, PCRE2_JIT_COMPLETE)) &&
        (ret != PCRE2_ERROR_JIT_BADOPTION))
    {
+      pcre2_get_error_message(ret, error_message, sizeof(error_message));
       log_error(LOG_LEVEL_ERROR,
-         "Unexpected error enabling JIT compilation for %s from %s: %s",
-         pattern, url->spec, rebuf);
+         "Failed to JIT-compile '%s' (%s) from '%s': %s",
+         pattern, rebuf, url->spec, error_message);
       freez(rebuf);
 
       return JB_ERR_PARSE;