Module: sip-router Branch: master Commit: dba9e85e137cc3818a01cccb2930e7580564ecd1 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dba9e85e...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Fri Jul 17 17:10:07 2009 +0200
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
---
route.c | 66 +++++++++++++++++++++++++++++++++----------------------------- 1 files changed, 35 insertions(+), 31 deletions(-)
diff --git a/route.c b/route.c index e22820d..effb608 100644 --- a/route.c +++ b/route.c @@ -525,6 +525,41 @@ int fix_expr(struct expr* exp) exp->op); } }else if (exp->type==ELEM_T){ + /* first fix & optimize rve/rvals (they might be optimized + to non-rvals, e.g. string, avp a.s.o) */ + if (exp->l_type==RVEXP_O){ + if ((ret=fix_rval_expr(&exp->l.param))<0){ + ERR("Unable to fix left rval expression\n"); + return ret; + } + if (scr_opt_lev>=2) + exp_optimize_left(exp); + } + if (exp->r_type==RVE_ST){ + if ((ret=fix_rval_expr(&exp->r.param))<0){ + ERR("Unable to fix right rval expression\n"); + return ret; + } + if (scr_opt_lev>=2) + exp_optimize_right(exp); + } + + /* Calculate lengths of strings */ + if (exp->l_type==STRING_ST) { + int len; + if (exp->l.string) len = strlen(exp->l.string); + else len = 0; + exp->l.str.s = exp->l.string; + exp->l.str.len = len; + } + if (exp->r_type==STRING_ST) { + int len; + if (exp->r.string) len = strlen(exp->r.string); + else len = 0; + exp->r.str.s = exp->r.string; + exp->r.str.len = len; + } + if (exp->op==MATCH_OP){ /* right side either has to be string, in which case * we turn it into regular expression, or it is regular @@ -562,21 +597,6 @@ int fix_expr(struct expr* exp) return ret; } } - /* Calculate lengths of strings */ - if (exp->l_type==STRING_ST) { - int len; - if (exp->l.string) len = strlen(exp->l.string); - else len = 0; - exp->l.str.s = exp->l.string; - exp->l.str.len = len; - } - if (exp->r_type==STRING_ST) { - int len; - if (exp->r.string) len = strlen(exp->r.string); - else len = 0; - exp->r.str.s = exp->r.string; - exp->r.str.len = len; - } if (exp->l_type==SELECT_O) { if ((ret=resolve_select(exp->l.select)) < 0) { BUG("Unable to resolve select\n"); @@ -591,22 +611,6 @@ int fix_expr(struct expr* exp) return ret; } } - if (exp->l_type==RVEXP_O){ - if ((ret=fix_rval_expr(&exp->l.param))<0){ - ERR("Unable to fix left rval expression\n"); - return ret; - } - if (scr_opt_lev>=2) - exp_optimize_left(exp); - } - if (exp->r_type==RVE_ST){ - if ((ret=fix_rval_expr(&exp->r.param))<0){ - ERR("Unable to fix right rval expression\n"); - return ret; - } - if (scr_opt_lev>=2) - exp_optimize_right(exp); - } /* PVAR don't need fixing */ ret=0; }