]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: pattern: ensure that sample types always cast into other types.
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Apr 2012 15:21:49 +0000 (17:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 18:57:17 +0000 (20:57 +0200)
We want to ensure that a dynamically returned type will always have a
cast before calling the cast function. This is done in pattern_process()
and in stktable_fetch_key().

src/pattern.c
src/stick_table.c

index f6afb9700c986176f05daf48bfd6d32020723951..2820cf60d65a336a45f919f555b30c79c2904b3e 100644 (file)
@@ -487,9 +487,21 @@ struct sample *pattern_process(struct proxy *px, struct session *l4, void *l7,
                return NULL;
 
        list_for_each_entry(conv_expr, &expr->conv_exprs, list) {
-               if (!pattern_casts[p->type][conv_expr->conv->in_type](p))
+               /* we want to ensure that p->type can be casted into
+                * conv_expr->conv->in_type. We have 3 possibilities :
+                *  - NULL   => not castable.
+                *  - c_none => nothing to do (let's optimize it)
+                *  - other  => apply cast and prepare to fail
+                */
+               if (!pattern_casts[p->type][conv_expr->conv->in_type])
                        return NULL;
 
+               if (pattern_casts[p->type][conv_expr->conv->in_type] != c_none &&
+                   !pattern_casts[p->type][conv_expr->conv->in_type](p))
+                       return NULL;
+
+               /* OK cast succeeded */
+
                /* force the output type after a cast */
                p->type = conv_expr->conv->in_type;
                if (!conv_expr->conv->process(conv_expr->arg_p, p))
index 7bff124e99f631804c3485d537547b6d6f7b33dc..a6ae3a29792ef7e1f30476bf1a7c24841740d44d 100644 (file)
@@ -600,6 +600,9 @@ struct stktable_key *stktable_fetch_key(struct stktable *t, struct proxy *px, st
        if (!smp)
                return NULL;
 
+       if (!pattern_to_key[smp->type][t->type])
+               return NULL;
+
        static_table_key.key_len = t->key_size;
        static_table_key.key = pattern_to_key[smp->type][t->type](smp, &static_table_key.data, &static_table_key.key_len);