[Xymon] Patch: PCRE2 support

Roland Rosenfeld roland at spinnaker.de
Mon Feb 12 12:36:16 CET 2024


Hi!

Sorry, to reply to myself, but I just found a bug in the patch, which
resulted in missing @RRDPARAM@ (line names) in the graphs (and maybe
other problems).

The root cause was, that pcre_copy_substring() returned the string
length on success while its replacement
pcre2_substring_copy_bynumber() returns zero on success.  As a result
the following changes are necessary:

 --- a/lib/acknowledgementslog.c
 +++ b/lib/acknowledgementslog.c
@@ -1083,7 +1084,7 @@ Last-Update: 2023-12-21
  			/* We have a matching file! */
  			rrddbs[rrddbcount].rrdfn = strdup(d->d_name);
 -			if (pcre_copy_substring(d->d_name, ovector, result, 1, param, sizeof(param)) > 0) {
-+			if (pcre2_substring_copy_bynumber(ovector, 1, param, &l) > 0) {
++			if (pcre2_substring_copy_bynumber(ovector, 1, param, &l) == 0) {
  				/*
  				 * This is ugly, but I cannot find a pretty way of un-mangling
  				 * the disk- and http-data that has been molested by the back-end.
@@ -1240,7 +1241,7 @@ Last-Update: 2023-12-21
  		char delaytxt[4096];
 -		if (pcre_copy_substring(subjectline, ovector, result, 1, delaytxt, sizeof(delaytxt)) > 0) {
 +		l = sizeof(delaytxt);
-+		if (pcre2_substring_copy_bynumber(ovector, 1, delaytxt, &l) > 0) {
++		if (pcre2_substring_copy_bynumber(ovector, 1, delaytxt, &l) == 0) {
  			duration = durationvalue(delaytxt);
  		}
  	}
@@ -1261,7 +1262,7 @@ Last-Update: 2023-12-21
  		char msgtxt[4096];
 -		if (pcre_copy_substring(subjectline, ovector, result, 1, msgtxt, sizeof(msgtxt)) > 0) {
 +		l = sizeof(msgtxt);
-+		if (pcre2_substring_copy_bynumber(ovector, 1, msgtxt, &l) > 0) {
++		if (pcre2_substring_copy_bynumber(ovector, 1, msgtxt, &l) == 0) {
  			firsttxtline = strdup(msgtxt);
  		}
  	}
diff --git a/web/showgraph.c b/web/showgraph.c
index c6b891e..b3741ac 100644
--- a/web/showgraph.c
+++ b/web/showgraph.c
@@ -1027,7 +1027,7 @@ void generate_graph(char *gdeffn, char *rrddir, char *graphfn)
 
 			/* We have a matching file! */
 			rrddbs[rrddbcount].rrdfn = strdup(d->d_name);
-			if (pcre2_substring_copy_bynumber(ovector, 1, param, &l) > 0) {
+			if (pcre2_substring_copy_bynumber(ovector, 1, param, &l) == 0) {
 				/*
 				 * This is ugly, but I cannot find a pretty way of un-mangling
 				 * the disk- and http-data that has been molested by the back-end.
diff --git a/xymond/xymon-mailack.c b/xymond/xymon-mailack.c
index 1c66942..7ee7cc0 100644
--- a/xymond/xymon-mailack.c
+++ b/xymond/xymon-mailack.c
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
 	if (result >= 0) {
 		char delaytxt[4096];
 		l = sizeof(delaytxt);
-		if (pcre2_substring_copy_bynumber(ovector, 1, delaytxt, &l) > 0) {
+		if (pcre2_substring_copy_bynumber(ovector, 1, delaytxt, &l) == 0) {
 			duration = durationvalue(delaytxt);
 		}
 	}
@@ -145,7 +145,7 @@ int main(int argc, char *argv[])
 	if (result >= 0) {
 		char msgtxt[4096];
 		l = sizeof(msgtxt);
-		if (pcre2_substring_copy_bynumber(ovector, 1, msgtxt, &l) > 0) {
+		if (pcre2_substring_copy_bynumber(ovector, 1, msgtxt, &l) == 0) {
 			firsttxtline = strdup(msgtxt);
 		}
 	}

An updated (merged) patch is attached.

Greetings
Roland
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 93_pcre2.patch
Type: text/x-diff
Size: 79319 bytes
Desc: not available
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20240212/c7dc9075/attachment.patch>


More information about the Xymon mailing list