1 diff -ur syslog-ng-syslog-ng-4.2.0.orig/CMakeLists.txt syslog-ng-syslog-ng-4.2.0/CMakeLists.txt
2 --- syslog-ng-syslog-ng-4.2.0.orig/CMakeLists.txt 2023-05-10 16:55:07.000000000 +0200
3 +++ syslog-ng-syslog-ng-4.2.0/CMakeLists.txt 2023-07-19 02:12:21.375815517 +0200
5 include(openssl_functions)
8 -pkg_check_modules(LIBPCRE REQUIRED libpcre)
9 +pkg_check_modules(LIBPCRE REQUIRED libpcre2-8)
12 set(SYSLOG_NG_ENABLE_TCP_WRAPPER 1)
13 diff -ur syslog-ng-syslog-ng-4.2.0.orig/configure.ac syslog-ng-syslog-ng-4.2.0/configure.ac
14 --- syslog-ng-syslog-ng-4.2.0.orig/configure.ac 2023-05-10 16:55:07.000000000 +0200
15 +++ syslog-ng-syslog-ng-4.2.0/configure.ac 2023-07-19 02:12:21.375815517 +0200
17 IVYKIS_MIN_VERSION="0.36.1"
18 IVYKIS_UPDATED_VERSION="0.39"
19 JSON_C_MIN_VERSION="0.9"
20 -PCRE_MIN_VERSION="6.1"
21 +PCRE2_MIN_VERSION="10.0"
22 LMC_MIN_VERSION="1.0.0"
23 LRMQ_MIN_VERSION="0.0.1"
24 LRC_MIN_VERSION="1.6.0"
25 @@ -1046,9 +1046,10 @@
29 -PKG_CHECK_MODULES(PCRE, libpcre >= $PCRE_MIN_VERSION,, PCRE_LIBS="")
30 -if test -z "$PCRE_LIBS"; then
31 - AC_MSG_ERROR(Cannot find pcre version >= $PCRE_MIN_VERSION it is a hard dependency from syslog-ng 3.6 onwards)
32 +PKG_CHECK_MODULES(PCRE2, libpcre2-8 >= $PCRE2_MIN_VERSION,, PCRE2_LIBS="")
34 +if test test -z "$PCRE2_LIBS"; then
35 + AC_MSG_ERROR(Cannot find pcre2 version >= $PCRE2_MIN_VERSION which is a hard dependency from syslog-ng 3.6 onwards)
38 dnl ***************************************************************************
40 python_moduledir="$moduledir"/python
41 python_sysconf_moduledir="${sysconfdir}/python"
43 -CPPFLAGS="$CPPFLAGS $GLIB_CFLAGS $EVTLOG_CFLAGS $PCRE_CFLAGS $OPENSSL_CFLAGS $LIBNET_CFLAGS $LIBDBI_CFLAGS $IVYKIS_CFLAGS $LIBCAP_CFLAGS -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
44 +CPPFLAGS="$CPPFLAGS $GLIB_CFLAGS $EVTLOG_CFLAGS $PCRE2_CFLAGS $OPENSSL_CFLAGS $LIBNET_CFLAGS $LIBDBI_CFLAGS $IVYKIS_CFLAGS $LIBCAP_CFLAGS -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
46 ########################################################
47 ## NOTES: on how syslog-ng is linked
49 MODULE_DEPS_LIBS="\$(top_builddir)/lib/libsyslog-ng.la"
51 if test "x$linking_mode" = "xdynamic"; then
52 - SYSLOGNG_DEPS_LIBS="$LIBS $BASE_LIBS $GLIB_LIBS $EVTLOG_LIBS $SECRETSTORAGE_LIBS $RESOLV_LIBS $LIBCAP_LIBS $PCRE_LIBS $REGEX_LIBS $DL_LIBS"
53 + SYSLOGNG_DEPS_LIBS="$LIBS $BASE_LIBS $GLIB_LIBS $EVTLOG_LIBS $SECRETSTORAGE_LIBS $RESOLV_LIBS $LIBCAP_LIBS $PCRE2_LIBS $REGEX_LIBS $DL_LIBS"
55 if test "x$with_ivykis" = "xinternal"; then
56 # when using the internal ivykis, we're linking it statically into libsyslog-ng.so
58 # syslog-ng binary is linked with the default link command (e.g. libtool)
59 SYSLOGNG_LINK='$(LINK)'
61 - SYSLOGNG_DEPS_LIBS="$LIBS $BASE_LIBS $RESOLV_LIBS $EVTLOG_NO_LIBTOOL_LIBS $SECRETSTORAGE_NO_LIBTOOL_LIBS $LD_START_STATIC -Wl,${WHOLE_ARCHIVE_OPT} $GLIB_LIBS $PCRE_LIBS $REGEX_LIBS -Wl,${NO_WHOLE_ARCHIVE_OPT} $IVYKIS_NO_LIBTOOL_LIBS $LD_END_STATIC $LIBCAP_LIBS $DL_LIBS"
62 - TOOL_DEPS_LIBS="$LIBS $BASE_LIBS $GLIB_LIBS $EVTLOG_LIBS $SECRETSTORAGE_LIBS $RESOLV_LIBS $LIBCAP_LIBS $PCRE_LIBS $REGEX_LIBS $IVYKIS_LIBS $DL_LIBS"
63 + SYSLOGNG_DEPS_LIBS="$LIBS $BASE_LIBS $RESOLV_LIBS $EVTLOG_NO_LIBTOOL_LIBS $SECRETSTORAGE_NO_LIBTOOL_LIBS $LD_START_STATIC -Wl,${WHOLE_ARCHIVE_OPT} $GLIB_LIBS $PCRE2_LIBS $REGEX_LIBS -Wl,${NO_WHOLE_ARCHIVE_OPT} $IVYKIS_NO_LIBTOOL_LIBS $LD_END_STATIC $LIBCAP_LIBS $DL_LIBS"
64 + TOOL_DEPS_LIBS="$LIBS $BASE_LIBS $GLIB_LIBS $EVTLOG_LIBS $SECRETSTORAGE_LIBS $RESOLV_LIBS $LIBCAP_LIBS $PCRE2_LIBS $REGEX_LIBS $IVYKIS_LIBS $DL_LIBS"
67 # bypass libtool in case we want to do mixed linking because it
68 diff -ur syslog-ng-syslog-ng-4.2.0.orig/lib/compat/pcre.h syslog-ng-syslog-ng-4.2.0/lib/compat/pcre.h
69 --- syslog-ng-syslog-ng-4.2.0.orig/lib/compat/pcre.h 2023-05-10 16:55:07.000000000 +0200
70 +++ syslog-ng-syslog-ng-4.2.0/lib/compat/pcre.h 2023-07-19 02:12:21.376815531 +0200
72 #define COMPAT_PCRE_H_INCLUDED
74 #include "compat/compat.h"
77 -#ifndef PCRE_CONFIG_JIT
78 -#define pcre_free_study pcre_free
81 -#ifndef PCRE_STUDY_JIT_COMPILE
82 -#define PCRE_STUDY_JIT_COMPILE 0
85 -#ifndef PCRE_NEWLINE_ANYCRLF
86 -#define PCRE_NEWLINE_ANYCRLF 0
88 +#define PCRE2_CODE_UNIT_WIDTH 8
91 #endif /* COMPAT_PCRE_H_INCLUDED */
92 diff -ur syslog-ng-syslog-ng-4.2.0.orig/lib/filter/tests/test_filters_regexp.c syslog-ng-syslog-ng-4.2.0/lib/filter/tests/test_filters_regexp.c
93 --- syslog-ng-syslog-ng-4.2.0.orig/lib/filter/tests/test_filters_regexp.c 2023-05-10 16:55:07.000000000 +0200
94 +++ syslog-ng-syslog-ng-4.2.0/lib/filter/tests/test_filters_regexp.c 2023-07-19 02:12:21.376815531 +0200
100 -check_pcre_version_is_atleast(const gchar *version)
102 - return strncmp(pcre_version(), version, strlen(version)) >= 0;
105 Test(filter, create_pcre_regexp_filter)
107 cr_assert_eq(create_pcre_regexp_filter(LM_V_PROGRAM, "((", 0), NULL);
109 cr_assert_eq(create_pcre_regexp_filter(LM_V_HOST, "(?iana", 0), NULL);
110 cr_assert_eq(create_pcre_regexp_match("((", 0), NULL);
111 cr_assert_eq(create_pcre_regexp_match("(?P<foo_123", 0), NULL); // Unterminated group identifier
112 - if (check_pcre_version_is_atleast("8.34"))
113 - cr_assert_eq(create_pcre_regexp_match("(?P<1>a)", 0), NULL); // Begins with a digit
114 + cr_assert_eq(create_pcre_regexp_match("(?P<1>a)", 0), NULL); // Begins with a digit
115 cr_assert_eq(create_pcre_regexp_match("(?P<!>a)", 0), NULL); // Begins with an illegal char
116 cr_assert_eq(create_pcre_regexp_match("(?P<foo!>a)", 0), NULL); // Ends with an illegal char
117 cr_assert_eq(create_pcre_regexp_match("\\1", 0), NULL); // Backreference
118 diff -ur syslog-ng-syslog-ng-4.2.0.orig/lib/logmatcher.c syslog-ng-syslog-ng-4.2.0/lib/logmatcher.c
119 --- syslog-ng-syslog-ng-4.2.0.orig/lib/logmatcher.c 2023-05-10 16:55:07.000000000 +0200
120 +++ syslog-ng-syslog-ng-4.2.0/lib/logmatcher.c 2023-07-19 02:12:21.376815531 +0200
121 @@ -281,87 +281,82 @@
122 typedef struct _LogMatcherPcreRe
127 + pcre2_code *pattern;
134 -_compile_pcre_regexp(LogMatcherPcreRe *self, const gchar *re, GError **error)
135 +_compile_pcre2_regexp(LogMatcherPcreRe *self, const gchar *re, GError **error)
138 - const gchar *errptr;
142 g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
144 if (self->super.flags & LMF_ICASE)
145 - flags |= PCRE_CASELESS;
146 + flags |= PCRE2_CASELESS;
148 if (self->super.flags & LMF_NEWLINE)
150 - if (!PCRE_NEWLINE_ANYCRLF)
151 + if (!PCRE2_NEWLINE_ANYCRLF)
152 msg_warning("syslog-ng was compiled against an old PCRE which doesn't support the 'newline' flag");
153 - flags |= PCRE_NEWLINE_ANYCRLF;
154 + flags |= PCRE2_NEWLINE_ANYCRLF;
156 if (self->super.flags & LMF_UTF8)
159 - flags |= PCRE_UTF8 | PCRE_NO_UTF8_CHECK;
160 - self->match_options |= PCRE_NO_UTF8_CHECK;
161 + flags |= PCRE2_UTF | PCRE2_NO_UTF_CHECK;
162 + self->match_options |= PCRE2_NO_UTF_CHECK;
164 - pcre_config(PCRE_CONFIG_UTF8, &support);
165 + pcre2_config(PCRE2_CONFIG_UNICODE, &support);
168 - g_set_error(error, LOG_TEMPLATE_ERROR, 0, "PCRE library is compiled without UTF8 support and utf8 flag was present");
169 + g_set_error(error, LOG_TEMPLATE_ERROR, 0, "PCRE library is compiled without unicode support and utf8 flag was present");
173 - pcre_config(PCRE_CONFIG_UNICODE_PROPERTIES, &support);
176 - g_set_error(error, LOG_TEMPLATE_ERROR, 0,
177 - "PCRE library is compiled without UTF8 properties support and utf8 flag was present");
181 if (self->super.flags & LMF_DUPNAMES)
183 - if (!PCRE_DUPNAMES)
184 + if (!PCRE2_DUPNAMES)
185 msg_warning("syslog-ng was compiled against an old PCRE which doesn't support the 'dupnames' flag");
186 - flags |= PCRE_DUPNAMES;
187 + flags |= PCRE2_DUPNAMES;
190 /* compile the regexp */
191 - self->pattern = pcre_compile2(re, flags, &rc, &errptr, &erroffset, NULL);
192 + PCRE2_SIZE error_offset;
194 + self->pattern = pcre2_compile((PCRE2_SPTR) re, PCRE2_ZERO_TERMINATED, flags, &rc, &error_offset, NULL);
197 + PCRE2_UCHAR error_message[128];
199 + pcre2_get_error_message(rc, error_message, sizeof(error_message));
200 g_set_error(error, LOG_TEMPLATE_ERROR, 0, "Failed to compile PCRE expression >>>%s<<< `%s' at character %d",
201 - re, errptr, erroffset);
202 + re, error_message, (gint) error_offset);
209 -_study_pcre_regexp(LogMatcherPcreRe *self, const gchar *re, GError **error)
210 +_jit_pcre2_regexp(LogMatcherPcreRe *self, const gchar *re, GError **error)
212 - const gchar *errptr;
215 - if ((self->super.flags & LMF_DISABLE_JIT) == 0)
216 - options |= PCRE_STUDY_JIT_COMPILE;
217 + if ((self->super.flags & LMF_DISABLE_JIT))
220 /* optimize regexp */
221 - self->extra = pcre_study(self->pattern, options, &errptr);
222 - if (errptr != NULL)
223 + gint rc = pcre2_jit_compile(self->pattern, PCRE2_JIT_COMPLETE);
226 - g_set_error(error, LOG_TEMPLATE_ERROR, 0, "Failed to optimize regular expression >>>%s<<< `%s'",
229 + PCRE2_UCHAR error_message[128];
231 + pcre2_get_error_message(rc, error_message, sizeof(error_message));
232 + msg_warning("Failed to JIT compile regular expression, you might want to use flags(disable-jit)",
233 + evt_tag_str("regexp", re),
234 + evt_tag_str("error", (gchar *) error_message));
238 @@ -374,10 +369,10 @@
239 g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
240 log_matcher_store_pattern(s, re);
242 - if (!_compile_pcre_regexp(self, re, error))
243 + if (!_compile_pcre2_regexp(self, re, error))
246 - if (!_study_pcre_regexp(self, re, error))
247 + if (!_jit_pcre2_regexp(self, re, error))
252 NVHandle source_handle;
253 const gchar *source_value;
254 gssize source_value_len;
257 + pcre2_match_data *match_data;
258 } LogMatcherPcreMatchResult;
261 @@ -434,11 +428,13 @@
262 log_matcher_pcre_re_feed_backrefs(LogMatcherPcreRe *self, LogMessage *msg, LogMatcherPcreMatchResult *result)
265 + guint32 num_matches = pcre2_get_ovector_count(result->match_data);
266 + PCRE2_SIZE *matches = pcre2_get_ovector_pointer(result->match_data);
268 - for (i = 0; i < (LOGMSG_MAX_MATCHES) && i < result->num_matches; i++)
269 + for (i = 0; i < (LOGMSG_MAX_MATCHES) && i < num_matches; i++)
271 - gint begin_index = result->matches[2 * i];
272 - gint end_index = result->matches[2 * i + 1];
273 + gint begin_index = matches[2 * i];
274 + gint end_index = matches[2 * i + 1];
276 if (begin_index < 0 || end_index < 0)
278 @@ -446,11 +442,11 @@
279 log_matcher_pcre_re_feed_value(self, msg, log_msg_get_match_handle(i), result, begin_index, end_index);
281 if (log_msg_is_handle_match(result->source_handle) &&
282 - log_msg_get_match_index(result->source_handle) >= result->num_matches)
283 + log_msg_get_match_index(result->source_handle) >= num_matches)
285 log_matcher_pcre_re_save_source_value_to_avoid_clobbering(result);
287 - log_msg_truncate_matches(msg, result->num_matches);
288 + log_msg_truncate_matches(msg, num_matches);
292 @@ -458,18 +454,20 @@
294 gchar *name_table = NULL;
296 - gint namecount = 0;
297 - gint name_entry_size = 0;
298 + guint32 namecount = 0;
299 + guint32 name_entry_size = 0;
301 - pcre_fullinfo(self->pattern, self->extra, PCRE_INFO_NAMECOUNT, &namecount);
302 + pcre2_pattern_info(self->pattern, PCRE2_INFO_NAMECOUNT, &namecount);
305 + PCRE2_SIZE *matches = pcre2_get_ovector_pointer(result->match_data);
308 /* Before we can access the substrings, we must extract the table for
309 translating names to numbers, and the size of each entry in the table.
311 - pcre_fullinfo(self->pattern, self->extra, PCRE_INFO_NAMETABLE, &name_table);
312 - pcre_fullinfo(self->pattern, self->extra, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
313 + pcre2_pattern_info(self->pattern, PCRE2_INFO_NAMETABLE, &name_table);
314 + pcre2_pattern_info(self->pattern, PCRE2_INFO_NAMEENTRYSIZE, &name_entry_size);
315 /* Now we can scan the table and, for each entry, print the number, the name,
316 and the substring itself.
319 for (i = 0; i < namecount; i++, tabptr += name_entry_size)
321 int n = (tabptr[0] << 8) | tabptr[1];
322 - gint begin_index = result->matches[2 * n];
323 - gint end_index = result->matches[2 * n + 1];
324 + gint begin_index = matches[2 * n];
325 + gint end_index = matches[2 * n + 1];
326 const gchar *namedgroup_name = tabptr + 2;
328 if (begin_index < 0 || end_index < 0)
329 @@ -502,30 +500,28 @@
330 LogMatcherPcreRe *self = (LogMatcherPcreRe *) s;
331 LogMatcherPcreMatchResult result;
333 + gboolean res = TRUE;
336 value_len = strlen(value);
338 - if (pcre_fullinfo(self->pattern, self->extra, PCRE_INFO_CAPTURECOUNT, &result.num_matches) < 0)
339 - g_assert_not_reached();
340 - if (result.num_matches > LOGMSG_MAX_MATCHES)
341 - result.num_matches = LOGMSG_MAX_MATCHES;
343 - gsize matches_size = 3 * (result.num_matches + 1);
344 - result.matches = g_alloca(matches_size * sizeof(gint));
345 + result.match_data = pcre2_match_data_create_from_pattern(self->pattern, NULL);
346 result.source_value = value;
347 result.source_value_len = value_len;
348 result.source_handle = value_handle;
350 - rc = pcre_exec(self->pattern, self->extra,
351 - result.source_value, result.source_value_len,
352 - 0, self->match_options,
353 - result.matches, matches_size);
354 + rc = pcre2_match(self->pattern,
355 + (PCRE2_SPTR) result.source_value,
356 + (PCRE2_SIZE) result.source_value_len,
358 + self->match_options,
365 - case PCRE_ERROR_NOMATCH:
366 + case PCRE2_ERROR_NOMATCH:
370 @@ -534,22 +530,22 @@
371 evt_tag_int("error_code", rc));
380 - msg_error("Error while storing matching substrings");
381 + msg_error("Error while storing matching substrings, more than 256 capture groups encountered");
385 - result.num_matches = rc;
386 if ((s->flags & LMF_STORE_MATCHES))
388 log_matcher_pcre_re_feed_backrefs(self, msg, &result);
389 log_matcher_pcre_re_feed_named_substrings(self, msg, &result);
393 + pcre2_match_data_free(result.match_data);
398 @@ -559,24 +555,19 @@
399 LogMatcherPcreRe *self = (LogMatcherPcreRe *) s;
400 LogMatcherPcreMatchResult result;
401 GString *new_value = NULL;
402 - gsize matches_size;
404 gint start_offset, last_offset;
406 gboolean last_match_was_empty;
408 - if (pcre_fullinfo(self->pattern, self->extra, PCRE_INFO_CAPTURECOUNT, &result.num_matches) < 0)
409 - g_assert_not_reached();
410 - if (result.num_matches > LOGMSG_MAX_MATCHES)
411 - result.num_matches = LOGMSG_MAX_MATCHES;
412 + result.match_data = pcre2_match_data_create_from_pattern(self->pattern, NULL);
413 + PCRE2_SIZE *matches = pcre2_get_ovector_pointer(result.match_data);
415 - matches_size = 3 * (result.num_matches + 1);
416 - result.matches = g_alloca(matches_size * sizeof(gint));
418 /* we need zero initialized offsets for the last match as the
419 * algorithm tries uses that as the base position */
421 - result.matches[0] = result.matches[1] = result.matches[2] = 0;
422 + matches[0] = matches[1] = 0;
425 value_len = strlen(value);
429 * A zero-length match can be as simple as "a*" which will be
430 - * returned unless PCRE_NOTEMPTY is specified.
431 + * returned unless PCRE2_NOTEMPTY is specified.
433 * By supporting zero-length matches, we basically make it
434 * possible to insert replacement between each incoming
435 @@ -617,17 +608,21 @@
436 * to see if a non-empty match can be found.
439 - options = PCRE_NOTEMPTY | PCRE_ANCHORED;
440 + options = PCRE2_NOTEMPTY | PCRE2_ANCHORED;
447 - rc = pcre_exec(self->pattern, self->extra,
448 - result.source_value, result.source_value_len,
449 - start_offset, (self->match_options | options), result.matches, matches_size);
450 - if (rc < 0 && rc != PCRE_ERROR_NOMATCH)
451 + rc = pcre2_match(self->pattern,
452 + (PCRE2_SPTR) result.source_value,
453 + (PCRE2_SIZE) result.source_value_len,
455 + (self->match_options | options),
458 + if (rc < 0 && rc != PCRE2_ERROR_NOMATCH)
460 msg_error("Error while matching regexp",
461 evt_tag_int("error_code", rc));
466 - if ((options & PCRE_NOTEMPTY) == 0)
467 + if ((options & PCRE2_NOTEMPTY) == 0)
469 /* we didn't match, even when we permitted to match the
470 * empty string. Nothing to find here, bail out */
471 @@ -651,31 +646,31 @@
472 last_match_was_empty = FALSE;
477 + msg_error("Error while storing matching substrings, more than 256 capture groups encountered");
482 - /* if the output array was too small, truncate the number of
483 - captures to LOGMSG_MAX_MATCHES */
486 - rc = matches_size / 3;
488 - result.num_matches = rc;
489 log_matcher_pcre_re_feed_backrefs(self, msg, &result);
490 log_matcher_pcre_re_feed_named_substrings(self, msg, &result);
493 new_value = g_string_sized_new(result.source_value_len);
494 /* append non-matching portion */
495 - g_string_append_len(new_value, &result.source_value[last_offset], result.matches[0] - last_offset);
496 + g_string_append_len(new_value, &result.source_value[last_offset], matches[0] - last_offset);
498 log_template_append_format(replacement, msg, &DEFAULT_TEMPLATE_EVAL_OPTIONS, new_value);
500 - last_match_was_empty = (result.matches[0] == result.matches[1]);
501 - start_offset = last_offset = result.matches[1];
502 + last_match_was_empty = (matches[0] == matches[1]);
503 + start_offset = last_offset = matches[1];
506 while (self->super.flags & LMF_GLOBAL && start_offset < result.source_value_len);
508 + pcre2_match_data_free(result.match_data);
512 /* append the last literal */
514 log_matcher_pcre_re_free(LogMatcher *s)
516 LogMatcherPcreRe *self = (LogMatcherPcreRe *) s;
517 - pcre_free_study(self->extra);
518 - pcre_free(self->pattern);
519 + pcre2_code_free(self->pattern);
520 log_matcher_free_method(s);
523 diff -ur syslog-ng-syslog-ng-4.2.0.orig/lib/multi-line/multi-line-pattern.c syslog-ng-syslog-ng-4.2.0/lib/multi-line/multi-line-pattern.c
524 --- syslog-ng-syslog-ng-4.2.0.orig/lib/multi-line/multi-line-pattern.c 2023-05-10 16:55:07.000000000 +0200
525 +++ syslog-ng-syslog-ng-4.2.0/lib/multi-line/multi-line-pattern.c 2023-07-19 02:12:21.376815531 +0200
527 * COPYING for details.
529 #include "multi-line/multi-line-pattern.h"
530 +#include "messages.h"
533 multi_line_pattern_compile(const gchar *regexp, GError **error)
535 MultiLinePattern *self = g_new0(MultiLinePattern, 1);
538 - const gchar *errptr;
540 + PCRE2_SIZE erroffset;
542 g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
545 /* compile the regexp */
546 - self->pattern = pcre_compile2(regexp, 0, &rc, &errptr, &erroffset, NULL);
547 + self->pattern = pcre2_compile((PCRE2_SPTR) regexp, PCRE2_ZERO_TERMINATED, 0, &rc, &erroffset, NULL);
550 - g_set_error(error, 0, 0, "Error while compiling multi-line regexp as a PCRE expression, error=%s, error_at=%d", errptr,
552 + PCRE2_UCHAR error_message[128];
554 + pcre2_get_error_message(rc, error_message, sizeof(error_message));
555 + g_set_error(error, 0, 0,
556 + "Error while compiling multi-line regexp as a PCRE expression, error=%s, error_at=%" G_GSIZE_FORMAT,
557 + (gchar *) error_message, erroffset);
561 -#ifdef PCRE_STUDY_JIT_COMPILE
562 - optflags = PCRE_STUDY_JIT_COMPILE;
565 /* optimize regexp */
566 - self->extra = pcre_study(self->pattern, optflags, &errptr);
567 - if (errptr != NULL)
568 + rc = pcre2_jit_compile(self->pattern, PCRE2_JIT_COMPLETE);
571 - g_set_error(error, 0, 0, "Error while studying multi-line regexp, error=%s", errptr);
573 + PCRE2_UCHAR error_message[128];
575 + pcre2_get_error_message(rc, error_message, sizeof(error_message));
576 + msg_warning("multi-line-pattern: Error while JIT compiling regular expression",
577 + evt_tag_str("regexp", regexp),
578 + evt_tag_str("error", (gchar *) error_message));
584 - pcre_free(self->pattern);
585 + pcre2_code_free(self->pattern);
591 -multi_line_pattern_find(MultiLinePattern *re, const guchar *str, gsize len, gint *matches, gint matches_num)
592 +multi_line_pattern_eval(MultiLinePattern *re, const guchar *str, gsize len, pcre2_match_data *match_data)
595 + return pcre2_match(re->pattern, (PCRE2_SPTR) str, (PCRE2_SIZE) len, 0, 0, match_data, NULL);
599 +multi_line_pattern_find(MultiLinePattern *re, const guchar *str, gsize len, gint *start, gint *end)
605 + gboolean result = FALSE;
606 + pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(re->pattern, NULL);
609 - rc = pcre_exec(re->pattern, re->extra, (const gchar *) str, len, 0, 0, matches, matches_num * 3);
611 + if (multi_line_pattern_eval(re, str, len, match_data) < 0)
614 + guint32 num_matches = pcre2_get_ovector_count(match_data);
615 + PCRE2_SIZE *matches = pcre2_get_ovector_pointer(match_data);
617 + if (num_matches == 0)
620 + *start = matches[0];
624 + pcre2_match_data_free(match_data);
629 multi_line_pattern_match(MultiLinePattern *re, const guchar *str, gsize len)
632 - if (multi_line_pattern_find(re, str, len, match, 1) < 0)
635 - return match[0] >= 0;
638 + gboolean result = FALSE;
639 + pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(re->pattern, NULL);
641 + if (multi_line_pattern_eval(re, str, len, match_data) < 0)
644 + guint32 num_matches = pcre2_get_ovector_count(match_data);
645 + PCRE2_SIZE *matches = pcre2_get_ovector_pointer(match_data);
647 + result = num_matches > 0 && matches[0] >= 0;
650 + pcre2_match_data_free(match_data);
655 multi_line_pattern_ref(MultiLinePattern *self)
657 if (self && (--self->ref_cnt == 0))
660 - pcre_free(self->pattern);
662 - pcre_free_study(self->extra);
663 + pcre2_code_free(self->pattern);
667 diff -ur syslog-ng-syslog-ng-4.2.0.orig/lib/multi-line/multi-line-pattern.h syslog-ng-syslog-ng-4.2.0/lib/multi-line/multi-line-pattern.h
668 --- syslog-ng-syslog-ng-4.2.0.orig/lib/multi-line/multi-line-pattern.h 2023-05-10 16:55:07.000000000 +0200
669 +++ syslog-ng-syslog-ng-4.2.0/lib/multi-line/multi-line-pattern.h 2023-07-19 02:12:21.376815531 +0200
671 struct _MultiLinePattern
676 + pcre2_code *pattern;
679 -gint multi_line_pattern_find(MultiLinePattern *re, const guchar *str, gsize len, gint *matches, gint matches_num);
680 +gboolean multi_line_pattern_find(MultiLinePattern *re, const guchar *str, gsize len, gint *start, gint *end);
681 gboolean multi_line_pattern_match(MultiLinePattern *re, const guchar *str, gsize len);
682 MultiLinePattern *multi_line_pattern_compile(const gchar *regexp, GError **error);
683 MultiLinePattern *multi_line_pattern_ref(MultiLinePattern *self);
684 diff -ur syslog-ng-syslog-ng-4.2.0.orig/lib/multi-line/regexp-multi-line.c syslog-ng-syslog-ng-4.2.0/lib/multi-line/regexp-multi-line.c
685 --- syslog-ng-syslog-ng-4.2.0.orig/lib/multi-line/regexp-multi-line.c 2023-05-10 16:55:07.000000000 +0200
686 +++ syslog-ng-syslog-ng-4.2.0/lib/multi-line/regexp-multi-line.c 2023-07-19 02:12:21.377815546 +0200
689 _prefix_garbage_get_offset_of_garbage(RegexpMultiLine *self, const guchar *line, gsize line_len)
692 - if (multi_line_pattern_find(self->garbage, line, line_len, match, 1) < 0)
695 + if (!multi_line_pattern_find(self->garbage, line, line_len, &start, &end))
702 _prefix_suffix_get_offset_of_garbage(RegexpMultiLine *self, const guchar *line, gsize line_len)
705 - if (multi_line_pattern_find(self->garbage, line, line_len, match, 1) < 0)
708 + if (!multi_line_pattern_find(self->garbage, line, line_len, &start, &end))
715 diff -ur syslog-ng-syslog-ng-4.2.0.orig/modules/basicfuncs/list-funcs.c syslog-ng-syslog-ng-4.2.0/modules/basicfuncs/list-funcs.c
716 --- syslog-ng-syslog-ng-4.2.0.orig/modules/basicfuncs/list-funcs.c 2023-05-10 16:55:07.000000000 +0200
717 +++ syslog-ng-syslog-ng-4.2.0/modules/basicfuncs/list-funcs.c 2023-07-19 02:12:21.377815546 +0200
719 StringMatchMode mode;
723 - pcre_extra *pcre_extra;
728 @@ -369,33 +368,35 @@
730 string_matcher_prepare_pcre(StringMatcher *self)
732 - const gchar *errptr;
734 + PCRE2_SIZE erroffset;
737 - self->pcre = pcre_compile2(self->pattern, PCRE_ANCHORED, &rc, &errptr, &erroffset, NULL);
738 + self->pcre = pcre2_compile((PCRE2_SPTR) self->pattern, PCRE2_ZERO_TERMINATED, PCRE2_ANCHORED, &rc, &erroffset, NULL);
741 + PCRE2_UCHAR error_message[128];
742 + pcre2_get_error_message(rc, error_message, sizeof(error_message));
744 msg_error("Error while compiling regular expression",
745 evt_tag_str("regular_expression", self->pattern),
746 evt_tag_str("error_at", &self->pattern[erroffset]),
747 evt_tag_int("error_offset", erroffset),
748 - evt_tag_str("error_message", errptr),
749 + evt_tag_str("error_message", (gchar *) error_message),
750 evt_tag_int("error_code", rc));
753 - self->pcre_extra = pcre_study(self->pcre, PCRE_STUDY_JIT_COMPILE, &errptr);
756 + /* optimize regexp */
757 + rc = pcre2_jit_compile(self->pcre, PCRE2_JIT_COMPLETE);
760 - msg_error("Error while optimizing regular expression",
761 - evt_tag_str("regular_expression", self->pattern),
762 - evt_tag_str("error_message", errptr));
763 - pcre_free(self->pcre);
764 - if (self->pcre_extra)
765 - pcre_free_study(self->pcre_extra);
768 + PCRE2_UCHAR error_message[128];
770 + pcre2_get_error_message(rc, error_message, sizeof(error_message));
771 + msg_warning("$(list-search): Failed to JIT compile regular expression",
772 + evt_tag_str("regexp", self->pattern),
773 + evt_tag_str("error", (gchar *) error_message));
780 string_matcher_match_pcre(StringMatcher *self, const char *string, gsize string_len)
782 - gint rc = pcre_exec(self->pcre, self->pcre_extra, string, string_len, 0, 0, NULL, 0);
783 - if (rc == PCRE_ERROR_NOMATCH)
784 + pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(self->pcre, NULL);
785 + gint rc = pcre2_match(self->pcre, (PCRE2_SPTR) string, (PCRE2_SIZE) string_len, 0, 0, match_data, NULL);
786 + pcre2_match_data_free(match_data);
788 + if (rc == PCRE2_ERROR_NOMATCH)
794 g_pattern_spec_free(self->glob);
796 - pcre_free(self->pcre);
797 - if (self->pcre_extra)
798 - pcre_free_study(self->pcre_extra);
799 + pcre2_code_free(self->pcre);
803 diff -ur syslog-ng-syslog-ng-4.2.0.orig/modules/basicfuncs/tests/test_basicfuncs.c syslog-ng-syslog-ng-4.2.0/modules/basicfuncs/tests/test_basicfuncs.c
804 --- syslog-ng-syslog-ng-4.2.0.orig/modules/basicfuncs/tests/test_basicfuncs.c 2023-05-10 16:55:07.000000000 +0200
805 +++ syslog-ng-syslog-ng-4.2.0/modules/basicfuncs/tests/test_basicfuncs.c 2023-07-19 02:12:21.377815546 +0200
808 assert_template_format(param->template, param->expected);
811 +Test(basicfuncs, test_performance)
813 + perftest_template("$(list-search --start-index 1 --mode pcre .az '\"foo,\",\"bar\",\"baz\"')");
815 diff -ur syslog-ng-syslog-ng-4.2.0.orig/modules/correlation/group-lines.c syslog-ng-syslog-ng-4.2.0/modules/correlation/group-lines.c
816 --- syslog-ng-syslog-ng-4.2.0.orig/modules/correlation/group-lines.c 2023-05-10 16:55:07.000000000 +0200
817 +++ syslog-ng-syslog-ng-4.2.0/modules/correlation/group-lines.c 2023-07-19 02:12:21.377815546 +0200
819 #include "messages.h"
820 #include "grouping-parser.h"
825 typedef struct _GroupLinesContext
826 diff -ur syslog-ng-syslog-ng-4.2.0.orig/modules/correlation/radix.c syslog-ng-syslog-ng-4.2.0/modules/correlation/radix.c
827 --- syslog-ng-syslog-ng-4.2.0.orig/modules/correlation/radix.c 2023-05-10 16:55:07.000000000 +0200
828 +++ syslog-ng-syslog-ng-4.2.0/modules/correlation/radix.c 2023-07-19 02:12:21.377815546 +0200
833 +#include "compat/pcre.h"
841 /**************************************************************
843 **************************************************************/
844 @@ -129,80 +128,80 @@
846 typedef struct _RParserPCREState
854 r_parser_pcre(gchar *str, gint *len, const gchar *param, gpointer state, RParserMatch *match)
856 RParserPCREState *self = (RParserPCREState *) state;
857 + gboolean result = FALSE;
861 - if (pcre_fullinfo(self->re, self->extra, PCRE_INFO_CAPTURECOUNT, &num_matches) < 0)
862 - g_assert_not_reached();
863 - if (num_matches > LOGMSG_MAX_MATCHES)
864 - num_matches = LOGMSG_MAX_MATCHES;
866 - gsize matches_size = 3 * (num_matches + 1);
867 - gint *matches = g_alloca(matches_size * sizeof(gint));
868 + pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(self->re, NULL);
869 + rc = pcre2_match(self->re, (PCRE2_SPTR) str, (PCRE2_SIZE) strlen(str), 0, 0, match_data, NULL);
871 - rc = pcre_exec(self->re, self->extra, str, strlen(str), 0, 0, matches, matches_size);
873 - if (rc == PCRE_ERROR_NOMATCH)
877 + if (rc == PCRE2_ERROR_NOMATCH)
882 msg_error("Error while matching regexp", evt_tag_int("error_code", rc));
889 msg_error("Error while storing matching substrings");
894 + PCRE2_SIZE *matches = pcre2_get_ovector_pointer(match_data);
896 *len = matches[1] - matches[0];
900 + pcre2_match_data_free(match_data);
905 r_parser_pcre_compile_state(const gchar *expr)
907 RParserPCREState *self = g_new0(RParserPCREState, 1);
908 - const gchar *errptr;
913 - self->re = pcre_compile2(expr, PCRE_ANCHORED, &rc, &errptr, &erroffset, NULL);
914 + self->re = pcre2_compile((PCRE2_SPTR)expr, PCRE2_ZERO_TERMINATED, PCRE2_ANCHORED, &rc, &erroffset, NULL);
917 + PCRE2_UCHAR error_message[128];
919 + pcre2_get_error_message(rc, error_message, sizeof(error_message));
921 msg_error("Error while compiling regular expression",
922 evt_tag_str("regular_expression", expr),
923 evt_tag_str("error_at", &expr[erroffset]),
924 evt_tag_int("error_offset", erroffset),
925 - evt_tag_str("error_message", errptr),
926 + evt_tag_str("error_message", (gchar *) error_message),
927 evt_tag_int("error_code", rc));
931 - self->extra = pcre_study(self->re, 0, &errptr);
934 + /* optimize regexp */
935 + rc = pcre2_jit_compile(self->re, PCRE2_JIT_COMPLETE);
938 - msg_error("Error while optimizing regular expression",
939 - evt_tag_str("regular_expression", expr),
940 - evt_tag_str("error_message", errptr));
941 - pcre_free(self->re);
943 - pcre_free(self->extra);
946 + PCRE2_UCHAR error_message[128];
948 + pcre2_get_error_message(rc, error_message, sizeof(error_message));
949 + msg_warning("radix: Error while JIT compiling regular expression",
950 + evt_tag_str("regular_expression", expr),
951 + evt_tag_str("error_message", (gchar *) error_message),
952 + evt_tag_int("error_code", rc));
955 return (gpointer) self;
959 RParserPCREState *self = (RParserPCREState *) s;
962 - pcre_free(self->re);
964 - pcre_free(self->extra);
965 + pcre2_code_free(self->re);
969 diff -ur syslog-ng-syslog-ng-4.2.0.orig/packaging/debian/control syslog-ng-syslog-ng-4.2.0/packaging/debian/control
970 --- syslog-ng-syslog-ng-4.2.0.orig/packaging/debian/control 2023-05-10 16:55:07.000000000 +0200
971 +++ syslog-ng-syslog-ng-4.2.0/packaging/debian/control 2023-07-19 02:12:21.377815546 +0200
974 libjson-c-dev | libjson0-dev,
978 libcap-dev [linux-any],
979 libsystemd-dev (>= 209) [linux-any],
981 diff -ur syslog-ng-syslog-ng-4.2.0.orig/packaging/rhel/syslog-ng.spec syslog-ng-syslog-ng-4.2.0/packaging/rhel/syslog-ng.spec
982 --- syslog-ng-syslog-ng-4.2.0.orig/packaging/rhel/syslog-ng.spec 2023-05-10 16:55:07.000000000 +0200
983 +++ syslog-ng-syslog-ng-4.2.0/packaging/rhel/syslog-ng.spec 2023-07-19 02:12:21.378815560 +0200
985 BuildRequires: libdbi-devel
986 BuildRequires: libnet-devel
987 BuildRequires: openssl-devel
988 -BuildRequires: pcre-devel
989 +BuildRequires: pcre2-devel
990 BuildRequires: libuuid-devel
991 BuildRequires: libesmtp-devel
992 BuildRequires: libcurl-devel