[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xymon] parsing bug in hobbit-clients.cfg (fixed patch)



On 11/19/2010 05:40 PM, Elmar Heeb wrote:
I have narrowed down the bug to the namematch subroutine in
lib/matching.c and attached a patch.

The last post had the wrong patch file (no idea how the spurious hunk got in). Anyway this is the patch that worked for me.

     -- Elmar


--
Dr. Elmar S. Heeb <heeb (at) phys.ethz.ch>   support: +41 44 633 26 68
IT Services Group, HPT D 19               voice: +41 44 633 25 91
Department of Physics, ETH Zurich        mobile: +41 79 628 75 24
CH-8093 Zurich, Switzerland              http://nic.phys.ethz.ch/
-----------------------------------------------------------------
Please consider the environment before printing this e-mail
diff --git a/lib/matching.c b/lib/matching.c
index 16453dd..24cd81d 100644
--- a/lib/matching.c
+++ b/lib/matching.c
@@ -70,7 +70,7 @@ int namematch(char *needle, char *haystack, pcre *pcrecode)
 {
 	char *xhay;
 	char *xneedle;
-	char *match;
+	char *xnotneedle;
 	int result = 0;
 
 	if (pcrecode) {
@@ -86,23 +86,22 @@ int namematch(char *needle, char *haystack, pcre *pcrecode)
 	/* Implement a simple, no-wildcard match */
 	xhay = malloc(strlen(haystack) + 3);
 	sprintf(xhay, ",%s,", haystack);
-	xneedle = malloc(strlen(needle)+2);
-	sprintf(xneedle, "%s,", needle);
-
-	match = strstr(xhay, xneedle);
-	if (match) {
-		if (*(match-1) == '!') {
-			/* Matched, but was a negative rule. */
-			result = 0;
-		}
-		else if (*(match-1) == ',') {
-			/* Matched */
-			result = 1;
-		}
-		else {
-			/* Matched a partial string. Fail. */
-			result = 0;
-		}
+	xneedle = malloc(strlen(needle)+3);
+	sprintf(xneedle, ",%s,", needle);
+	xnotneedle = malloc(strlen(needle)+4);
+	sprintf(xnotneedle, ",!%s,", needle);
+
+	if (strstr(xhay, xnotneedle)) {
+		/* 
+		 * match with a '!' prefix means "no match"
+		 */
+		result = 0;
+	}
+	else if (strstr(xhay, xneedle)) {
+		/*
+		 * "match" where ',' before and after ensure full match
+		 */
+		result = 1;
 	}
 	else {
 		/*