Browse code

Comparing string results of @select or $avp expression with numeric value. Test like "123" > 100 is not allowed by cfg.y rules, but $test > 10 is.

NOTE: the right operator MUST be number to do the numeric comparison.

Michal Matyska authored on 18/03/2006 23:40:15
Showing 1 changed files
... ...
@@ -73,7 +73,7 @@
73 73
 #include "select.h"
74 74
 #include "onsend.h"
75 75
 #include "hashes.h"
76
-
76
+#include "ut.h"
77 77
 
78 78
 #define RT_HASH_SIZE	8 /* route names hash */
79 79
 
... ...
@@ -584,7 +584,8 @@ inline static int comp_str(int op, str* left, int rtype, union exp_op* r, struct
584 584
 	int ret;
585 585
 	char backup;
586 586
 	regex_t* re;
587
-
587
+	unsigned int l;
588
+	
588 589
 	right=0; /* warning fix */
589 590
 
590 591
 	if (rtype == AVP_ST) {
... ...
@@ -599,6 +600,14 @@ inline static int comp_str(int op, str* left, int rtype, union exp_op* r, struct
599 599
 	} else if ((op == MATCH_OP && rtype == RE_ST)) {
600 600
 	} else if (op != MATCH_OP && rtype == STRING_ST) {
601 601
 		right = &r->str;
602
+	} else if (rtype == NUMBER_ST) {
603
+			/* "123" > 100 is not allowed by cfg.y rules
604
+			 * but can happen as @select or $avp evaluation
605
+			 * $test > 10
606
+			 * the right operator MUST be number to do the conversion
607
+			 */
608
+		str2int(left,&l);
609
+		return comp_num(op, l, rtype, r);
602 610
 	} else {
603 611
 		LOG(L_CRIT, "BUG: comp_str: Bad type %d, "
604 612
 		    "string or RE expected\n", rtype);