BUG/MEDIUM: map/acl: fix unwanted flags inheritance.

The bug: Maps/ACLs using the same file/id can mistakenly inherit
their flags from the last declared one.

i.e.

    $ cat haproxy.conf
    listen mylistener
	mode http
	bind 0.0.0.0:8080

	acl myacl1 url -i -f mine.acl
	acl myacl2 url -f mine.acl
	acl myacl3 url -i -f mine.acl
	redirect location / if myacl2
    $ cat mine.acl
    foobar

Shows an unexpected redirect for request 'GET /FOObAR HTTP/1.0\n\n'.

This fix should be backported on mainline branches v1.6 and v1.7.
This commit is contained in:
Emeric Brun 2017-07-03 17:54:23 +02:00 committed by Willy Tarreau
parent e0ee0be4e7
commit 7d27f3c12d
3 changed files with 9 additions and 9 deletions

View File

@ -209,7 +209,7 @@ int pattern_read_from_file(struct pattern_head *head, unsigned int refflags, con
void pattern_init_expr(struct pattern_expr *expr);
struct pattern_expr *pattern_lookup_expr(struct pattern_head *head, struct pat_ref *ref);
struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref *ref,
char **err, int *reuse);
int patflags, char **err, int *reuse);
struct sample_data **pattern_find_smp(struct pattern_expr *expr, struct pat_ref_elt *elt);
int pattern_delete(struct pattern_expr *expr, struct pat_ref_elt *ref);

View File

@ -536,13 +536,10 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
}
/* Create new pattern expression associated to this reference. */
pattern_expr = pattern_new_expr(&expr->pat, ref, err, NULL);
pattern_expr = pattern_new_expr(&expr->pat, ref, patflags, err, NULL);
if (!pattern_expr)
goto out_free_expr;
/* Copy the pattern matching and indexing flags. */
pattern_expr->mflags = patflags;
/* now parse all patterns */
while (**args) {
arg = *args;

View File

@ -2065,7 +2065,7 @@ struct pattern_expr *pattern_lookup_expr(struct pattern_head *head, struct pat_r
* flag <reuse> is set.
*/
struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref *ref,
char **err, int *reuse)
int patflags, char **err, int *reuse)
{
struct pattern_expr *expr;
struct pattern_expr_list *list;
@ -2088,7 +2088,8 @@ struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref
list_for_each_entry(expr, &ref->pat, list)
if (expr->pat_head->index == head->index &&
expr->pat_head->parse == head->parse &&
expr->pat_head->parse_smp == head->parse_smp)
expr->pat_head->parse_smp == head->parse_smp &&
expr->mflags == patflags)
break;
if (&expr->list == &ref->pat)
expr = NULL;
@ -2109,6 +2110,9 @@ struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref
/* Initialize this new expr. */
pattern_init_expr(expr);
/* Copy the pattern matching and indexing flags. */
expr->mflags = patflags;
/* This new pattern expression reference one of his heads. */
expr->pat_head = head;
@ -2377,10 +2381,9 @@ int pattern_read_from_file(struct pattern_head *head, unsigned int refflags,
*/
expr = pattern_lookup_expr(head, ref);
if (!expr || (expr->mflags != patflags)) {
expr = pattern_new_expr(head, ref, err, &reuse);
expr = pattern_new_expr(head, ref, patflags, err, &reuse);
if (!expr)
return 0;
expr->mflags = patflags;
}
/* The returned expression may be not empty, because the function