summaryrefslogtreecommitdiff
path: root/filter/filter.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2010-03-19 09:41:18 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2010-03-19 09:41:18 +0100
commitaa4612480424ad2fede0cd4ae4c7a893f61c6c0f (patch)
tree8241b7e72a8eb2f243f566cd81b072ccdb8ca183 /filter/filter.c
parent74e9331fe0892c4c96b4c4d7db3f14bb7e9d928e (diff)
Clear local variables in filters and functions.
Fixes crash when used uninitialized variables. This problem was surprisingly tricky to fix.
Diffstat (limited to 'filter/filter.c')
-rw-r--r--filter/filter.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/filter/filter.c b/filter/filter.c
index bfb480ab..de7a97bc 100644
--- a/filter/filter.c
+++ b/filter/filter.c
@@ -473,27 +473,10 @@ interpret(struct f_inst *what)
case 's':
ARG(v2, a2.p);
sym = what->a1.p;
- switch (res.type = v2.type) {
- case T_VOID: runtime( "Can't assign void values" );
- case T_ENUM:
- case T_BOOL:
- case T_INT:
- case T_PAIR:
- case T_STRING:
- case T_IP:
- case T_PREFIX:
- case T_PREFIX_SET:
- case T_SET:
- case T_PATH:
- case T_PATH_MASK:
- case T_CLIST:
- if (sym->class != (SYM_VARIABLE | v2.type))
- runtime( "Assigning to variable of incompatible type" );
- * (struct f_val *) sym->def = v2;
- break;
- default:
- bug( "Set to invalid type" );
- }
+ if ((sym->class != (SYM_VARIABLE | v2.type)) &&
+ (v2.type != T_VOID))
+ runtime( "Assigning to variable of incompatible type" );
+ * (struct f_val *) sym->def = v2;
break;
/* some constants have value in a2, some in *a1.p, strange. */
@@ -766,6 +749,10 @@ interpret(struct f_inst *what)
return res;
res.type &= ~T_RETURN;
break;
+ case P('c','v'): /* Clear local variables */
+ for (sym = what->a1.p; sym != NULL; sym = sym->aux2)
+ ((struct f_val *) sym->def)->type = T_VOID;
+ break;
case P('S','W'):
ONEARG;
{
@@ -948,6 +935,7 @@ i_same(struct f_inst *f1, struct f_inst *f2)
return 0;
f2->a2.p = f1->a2.p;
break;
+ case P('c','v'): break; /* internal instruction */
case P('S','W'): ONEARG; if (!same_tree(f1->a2.p, f2->a2.p)) return 0; break;
case P('i','M'): TWOARGS; break;
case P('A','p'): TWOARGS; break;