BUG/MAJOR: map: fix segfault during 'show map/acl' on cli.
The reference of the current map/acl element to dump could
be destroyed if map is updated from an 'http-request del-map'
configuration rule or throught a 'del map/acl' on CLI.
We use a 'back_refs' chaining element to fix this. As it
is done to dump sessions.
This patch needs also fix:
'BUG/MAJOR: cli: fix custom io_release was crushed by NULL.'
To clean the back_ref and avoid a crash on a further
del/clear map operation.
Those fixes should be backported on mainline branches 1.7 and 1.6.
This patch wont directly apply on 1.6.
diff --git a/src/pattern.c b/src/pattern.c
index 60fe462..2059309 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -1581,10 +1581,22 @@
{
struct pattern_expr *expr;
struct pat_ref_elt *elt, *safe;
+ struct bref *bref, *back;
/* delete pattern from reference */
list_for_each_entry_safe(elt, safe, &ref->head, list) {
if (elt == refelt) {
+ list_for_each_entry_safe(bref, back, &elt->back_refs, users) {
+ /*
+ * we have to unlink all watchers. We must not relink them if
+ * this elt was the last one in the list.
+ */
+ LIST_DEL(&bref->users);
+ LIST_INIT(&bref->users);
+ if (elt->list.n != &ref->head)
+ LIST_ADDQ(&LIST_ELEM(elt->list.n, struct stream *, list)->back_refs, &bref->users);
+ bref->ref = elt->list.n;
+ }
list_for_each_entry(expr, &ref->pat, list)
pattern_delete(expr, elt);
@@ -1606,11 +1618,23 @@
{
struct pattern_expr *expr;
struct pat_ref_elt *elt, *safe;
+ struct bref *bref, *back;
int found = 0;
/* delete pattern from reference */
list_for_each_entry_safe(elt, safe, &ref->head, list) {
if (strcmp(key, elt->pattern) == 0) {
+ list_for_each_entry_safe(bref, back, &elt->back_refs, users) {
+ /*
+ * we have to unlink all watchers. We must not relink them if
+ * this elt was the last one in the list.
+ */
+ LIST_DEL(&bref->users);
+ LIST_INIT(&bref->users);
+ if (elt->list.n != &ref->head)
+ LIST_ADDQ(&LIST_ELEM(elt->list.n, struct stream *, list)->back_refs, &bref->users);
+ bref->ref = elt->list.n;
+ }
list_for_each_entry(expr, &ref->pat, list)
pattern_delete(expr, elt);
@@ -1853,6 +1877,7 @@
else
elt->sample = NULL;
+ LIST_INIT(&elt->back_refs);
LIST_ADDQ(&ref->head, &elt->list);
return 1;
@@ -1948,6 +1973,7 @@
else
elt->sample = NULL;
+ LIST_INIT(&elt->back_refs);
LIST_ADDQ(&ref->head, &elt->list);
list_for_each_entry(expr, &ref->pat, list) {
@@ -1995,8 +2021,20 @@
{
struct pat_ref_elt *elt, *safe;
struct pattern_expr *expr;
+ struct bref *bref, *back;
list_for_each_entry_safe(elt, safe, &ref->head, list) {
+ list_for_each_entry_safe(bref, back, &elt->back_refs, users) {
+ /*
+ * we have to unlink all watchers. We must not relink them if
+ * this elt was the last one in the list.
+ */
+ LIST_DEL(&bref->users);
+ LIST_INIT(&bref->users);
+ if (elt->list.n != &ref->head)
+ LIST_ADDQ(&LIST_ELEM(elt->list.n, struct stream *, list)->back_refs, &bref->users);
+ bref->ref = elt->list.n;
+ }
LIST_DEL(&elt->list);
free(elt->pattern);
free(elt->sample);