Browse code

core: expr =~ fixup order fix

The fixup for built-in expressions were in the wrong order: first
RE and then RVE/RVALs, but a RVE/RVALs could be optimized away to
a string => because of the wrong order at runtime the match
operator might end up being used with a normal string instead of a
RE.
Now the order is RVE/RVALs fixup & optimisations, string fixups
(len) and then RE fixups (so that by the time the RE fixup is run
we know the final type of its operand).

Reported-by: Nils Ohlmeier nils at iptel org

Andrei Pelinescu-Onciul authored on 17/07/2009 15:10:07
Showing 1 changed files
... ...
@@ -525,6 +525,41 @@ int fix_expr(struct expr* exp)
525 525
 								exp->op);
526 526
 		}
527 527
 	}else if (exp->type==ELEM_T){
528
+			/* first fix & optimize rve/rvals (they might be optimized
529
+			   to non-rvals, e.g. string, avp a.s.o) */
530
+			if (exp->l_type==RVEXP_O){
531
+				if ((ret=fix_rval_expr(&exp->l.param))<0){
532
+					ERR("Unable to fix left rval expression\n");
533
+					return ret;
534
+				}
535
+				if (scr_opt_lev>=2)
536
+					exp_optimize_left(exp);
537
+			}
538
+			if (exp->r_type==RVE_ST){
539
+				if ((ret=fix_rval_expr(&exp->r.param))<0){
540
+					ERR("Unable to fix right rval expression\n");
541
+					return ret;
542
+				}
543
+				if (scr_opt_lev>=2)
544
+					exp_optimize_right(exp);
545
+			}
546
+			
547
+			/* Calculate lengths of strings */
548
+			if (exp->l_type==STRING_ST) {
549
+				int len;
550
+				if (exp->l.string) len = strlen(exp->l.string);
551
+				else len = 0;
552
+				exp->l.str.s = exp->l.string;
553
+				exp->l.str.len = len;
554
+			}
555
+			if (exp->r_type==STRING_ST) {
556
+				int len;
557
+				if (exp->r.string) len = strlen(exp->r.string);
558
+				else len = 0;
559
+				exp->r.str.s = exp->r.string;
560
+				exp->r.str.len = len;
561
+			}
562
+			
528 563
 			if (exp->op==MATCH_OP){
529 564
 				     /* right side either has to be string, in which case
530 565
 				      * we turn it into regular expression, or it is regular
... ...
@@ -562,21 +597,6 @@ int fix_expr(struct expr* exp)
562 562
 					return ret;
563 563
 				}
564 564
 			}
565
-			     /* Calculate lengths of strings */
566
-			if (exp->l_type==STRING_ST) {
567
-				int len;
568
-				if (exp->l.string) len = strlen(exp->l.string);
569
-				else len = 0;
570
-				exp->l.str.s = exp->l.string;
571
-				exp->l.str.len = len;
572
-			}
573
-			if (exp->r_type==STRING_ST) {
574
-				int len;
575
-				if (exp->r.string) len = strlen(exp->r.string);
576
-				else len = 0;
577
-				exp->r.str.s = exp->r.string;
578
-				exp->r.str.len = len;
579
-			}
580 565
 			if (exp->l_type==SELECT_O) {
581 566
 				if ((ret=resolve_select(exp->l.select)) < 0) {
582 567
 					BUG("Unable to resolve select\n");
... ...
@@ -591,22 +611,6 @@ int fix_expr(struct expr* exp)
591 591
 					return ret;
592 592
 				}
593 593
 			}
594
-			if (exp->l_type==RVEXP_O){
595
-				if ((ret=fix_rval_expr(&exp->l.param))<0){
596
-					ERR("Unable to fix left rval expression\n");
597
-					return ret;
598
-				}
599
-				if (scr_opt_lev>=2)
600
-					exp_optimize_left(exp);
601
-			}
602
-			if (exp->r_type==RVE_ST){
603
-				if ((ret=fix_rval_expr(&exp->r.param))<0){
604
-					ERR("Unable to fix right rval expression\n");
605
-					return ret;
606
-				}
607
-				if (scr_opt_lev>=2)
608
-					exp_optimize_right(exp);
609
-			}
610 594
 			/* PVAR don't need fixing */
611 595
 			ret=0;
612 596
 	}