]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: pattern: fixup use_after_free in the pat_ref_delete_by_id
authorpeter cai <peter.cai008@gmail.com>
Wed, 7 Oct 2015 07:07:43 +0000 (00:07 -0700)
committerWilly Tarreau <w@1wt.eu>
Tue, 13 Oct 2015 16:31:49 +0000 (18:31 +0200)
I found there is use_after_free bug in the pat_ref_delete_by_id.

[wt: it seems this fix must be backported to 1.5 as well]

src/pattern.c

index 07e1a524d93dbefd5eaa14039a5b826f2f023fe5..254c10650ed2967c76611357b86a736f4a1ec977 100644 (file)
@@ -1540,14 +1540,13 @@ int pat_ref_delete_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt)
        /* delete pattern from reference */
        list_for_each_entry_safe(elt, safe, &ref->head, list) {
                if (elt == refelt) {
+                       list_for_each_entry(expr, &ref->pat, list)
+                               pattern_delete(expr, elt);
+
                        LIST_DEL(&elt->list);
                        free(elt->sample);
                        free(elt->pattern);
                        free(elt);
-
-                       list_for_each_entry(expr, &ref->pat, list)
-                               pattern_delete(expr, elt);
-
                        return 1;
                }
        }