]> git.proxmox.com Git - qemu.git/commitdiff
acl: Fix use after free in qemu_acl_reset()
authorMarkus Armbruster <armbru@redhat.com>
Fri, 28 Oct 2011 15:07:02 +0000 (17:07 +0200)
committerStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Tue, 1 Nov 2011 06:23:48 +0000 (06:23 +0000)
Reproducer:

    $ MALLOC_PERTURB_=234 qemu-system-x86_64 -vnc :0,acl,sasl [...]
    QEMU 0.15.50 monitor - type 'help' for more information
    (qemu) acl_add vnc.username fred allow
    acl: added rule at position 1
    (qemu) acl_reset vnc.username
    Segmentation fault (core dumped)

Spotted by Coverity.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
acl.c

diff --git a/acl.c b/acl.c
index 0654f38f72775dae42cfa2a12eeace75cf370067..e840b9b6339a635e13a8d5b4038eba7b9601ba92 100644 (file)
--- a/acl.c
+++ b/acl.c
@@ -95,13 +95,13 @@ int qemu_acl_party_is_allowed(qemu_acl *acl,
 
 void qemu_acl_reset(qemu_acl *acl)
 {
-    qemu_acl_entry *entry;
+    qemu_acl_entry *entry, *next_entry;
 
     /* Put back to deny by default, so there is no window
      * of "open access" while the user re-initializes the
      * access control list */
     acl->defaultDeny = 1;
-    QTAILQ_FOREACH(entry, &acl->entries, next) {
+    QTAILQ_FOREACH_SAFE(entry, &acl->entries, next, next_entry) {
         QTAILQ_REMOVE(&acl->entries, entry, next);
         free(entry->match);
         free(entry);