]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: pattern: fix possible infinite loops on deletion
authorWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 09:49:01 +0000 (11:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 09:49:01 +0000 (11:49 +0200)
Commit e36b3b60b3 ("MEDIUM: migrate the patterns reference to cebs_tree")
changed the construction of the loops used to look up matching nodes, and
since we don't need two elements anymore, the "continue" statement now
loops on the same element when deleting. Let's fix this to make sure it
passes through the next one.

No backport is needed, this is only 3.3.

src/pattern.c

index 9971841394c46e843aacdf2a67aec86713af94a2..c740dbe8abc012523c4bd2ddca6a8cc45f4c674e 100644 (file)
@@ -1626,18 +1626,16 @@ int pat_ref_delete_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt)
  */
 int pat_ref_gen_delete(struct pat_ref *ref, unsigned int gen_id, const char *key)
 {
-       struct pat_ref_elt *elt, *next;
+       struct pat_ref_elt *elt;
        int found = 0;
 
        /* delete pattern from reference */
-       elt = cebs_item_lookup(&ref->ceb_root, node, pattern, key, struct pat_ref_elt);
-       while (elt) {
+       for (elt = cebs_item_lookup(&ref->ceb_root, node, pattern, key, struct pat_ref_elt);
+            elt; elt = cebs_item_next_dup(&ref->ceb_root, node, pattern, elt)) {
                if (elt->gen_id != gen_id)
                        continue;
-               next = cebs_item_next_dup(&ref->ceb_root, node, pattern, elt);
                pat_ref_delete_by_ptr(ref, elt);
                found = 1;
-               elt = next;
        }
 
        if (found)
@@ -1797,7 +1795,7 @@ static int pat_ref_set_from_elt(struct pat_ref *ref, struct pat_ref_elt *elt, co
                        gen = elt->gen_id;
                else if (elt->gen_id != gen) {
                        /* only consider duplicate elements from the same gen! */
-                       continue;
+                       goto skip;
                }
 
                if (!pat_ref_set_elt(ref, elt, value, &tmp_err)) {
@@ -1809,6 +1807,7 @@ static int pat_ref_set_from_elt(struct pat_ref *ref, struct pat_ref_elt *elt, co
                }
                found = 1;
                first = 0;
+       skip:
                elt = cebs_item_next_dup(&ref->ceb_root, node, pattern, elt);
        }