]> git.proxmox.com Git - qemu.git/blobdiff - acl.c
ehci: Fix NULL ptr deref when unplugging an USB dev with an iso stream active
[qemu.git] / acl.c
diff --git a/acl.c b/acl.c
index 173bf95b05e2cfa4b05e320bfcc18a6a3e95d9f8..e840b9b6339a635e13a8d5b4038eba7b9601ba92 100644 (file)
--- a/acl.c
+++ b/acl.c
 
 
 #include "qemu-common.h"
-#include "sysemu.h"
 #include "acl.h"
 
-#ifdef HAVE_FNMATCH_H
+#ifdef CONFIG_FNMATCH
 #include <fnmatch.h>
 #endif
 
@@ -41,8 +40,8 @@ qemu_acl *qemu_acl_find(const char *aclname)
 {
     int i;
     for (i = 0 ; i < nacls ; i++) {
-       if (strcmp(acls[i]->aclname, aclname) == 0)
-           return acls[i];
+        if (strcmp(acls[i]->aclname, aclname) == 0)
+            return acls[i];
     }
 
     return NULL;
@@ -54,19 +53,19 @@ qemu_acl *qemu_acl_init(const char *aclname)
 
     acl = qemu_acl_find(aclname);
     if (acl)
-       return acl;
+        return acl;
 
-    acl = qemu_malloc(sizeof(*acl));
-    acl->aclname = qemu_strdup(aclname);
+    acl = g_malloc(sizeof(*acl));
+    acl->aclname = g_strdup(aclname);
     /* Deny by default, so there is no window of "open
      * access" between QEMU starting, and the user setting
      * up ACLs in the monitor */
     acl->defaultDeny = 1;
 
     acl->nentries = 0;
-    TAILQ_INIT(&acl->entries);
+    QTAILQ_INIT(&acl->entries);
 
-    acls = qemu_realloc(acls, sizeof(*acls) * (nacls +1));
+    acls = g_realloc(acls, sizeof(*acls) * (nacls +1));
     acls[nacls] = acl;
     nacls++;
 
@@ -74,19 +73,19 @@ qemu_acl *qemu_acl_init(const char *aclname)
 }
 
 int qemu_acl_party_is_allowed(qemu_acl *acl,
-                             const char *party)
+                              const char *party)
 {
     qemu_acl_entry *entry;
 
-    TAILQ_FOREACH(entry, &acl->entries, next) {
-#ifdef HAVE_FNMATCH_H
-       if (fnmatch(entry->match, party, 0) == 0)
-           return entry->deny ? 0 : 1;
+    QTAILQ_FOREACH(entry, &acl->entries, next) {
+#ifdef CONFIG_FNMATCH
+        if (fnmatch(entry->match, party, 0) == 0)
+            return entry->deny ? 0 : 1;
 #else
-       /* No fnmatch, so fallback to exact string matching
-        * instead of allowing wildcards */
-       if (strcmp(entry->match, party) == 0)
-           return entry->deny ? 0 : 1;
+        /* No fnmatch, so fallback to exact string matching
+         * instead of allowing wildcards */
+        if (strcmp(entry->match, party) == 0)
+            return entry->deny ? 0 : 1;
 #endif
     }
 
@@ -96,32 +95,32 @@ 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;
-    TAILQ_FOREACH(entry, &acl->entries, next) {
-       TAILQ_REMOVE(&acl->entries, entry, next);
-       free(entry->match);
-       free(entry);
+    QTAILQ_FOREACH_SAFE(entry, &acl->entries, next, next_entry) {
+        QTAILQ_REMOVE(&acl->entries, entry, next);
+        free(entry->match);
+        free(entry);
     }
     acl->nentries = 0;
 }
 
 
 int qemu_acl_append(qemu_acl *acl,
-                   int deny,
-                   const char *match)
+                    int deny,
+                    const char *match)
 {
     qemu_acl_entry *entry;
 
-    entry = qemu_malloc(sizeof(*entry));
-    entry->match = qemu_strdup(match);
+    entry = g_malloc(sizeof(*entry));
+    entry->match = g_strdup(match);
     entry->deny = deny;
 
-    TAILQ_INSERT_TAIL(&acl->entries, entry, next);
+    QTAILQ_INSERT_TAIL(&acl->entries, entry, next);
     acl->nentries++;
 
     return acl->nentries;
@@ -129,48 +128,48 @@ int qemu_acl_append(qemu_acl *acl,
 
 
 int qemu_acl_insert(qemu_acl *acl,
-                   int deny,
-                   const char *match,
-                   int index)
+                    int deny,
+                    const char *match,
+                    int index)
 {
     qemu_acl_entry *entry;
     qemu_acl_entry *tmp;
     int i = 0;
 
     if (index <= 0)
-       return -1;
+        return -1;
     if (index >= acl->nentries)
-       return qemu_acl_append(acl, deny, match);
+        return qemu_acl_append(acl, deny, match);
 
 
-    entry = qemu_malloc(sizeof(*entry));
-    entry->match = qemu_strdup(match);
+    entry = g_malloc(sizeof(*entry));
+    entry->match = g_strdup(match);
     entry->deny = deny;
 
-    TAILQ_FOREACH(tmp, &acl->entries, next) {
-       i++;
-       if (i == index) {
-           TAILQ_INSERT_BEFORE(tmp, entry, next);
-           acl->nentries++;
-           break;
-       }
+    QTAILQ_FOREACH(tmp, &acl->entries, next) {
+        i++;
+        if (i == index) {
+            QTAILQ_INSERT_BEFORE(tmp, entry, next);
+            acl->nentries++;
+            break;
+        }
     }
 
     return i;
 }
 
 int qemu_acl_remove(qemu_acl *acl,
-                   const char *match)
+                    const char *match)
 {
     qemu_acl_entry *entry;
     int i = 0;
 
-    TAILQ_FOREACH(entry, &acl->entries, next) {
-       i++;
-       if (strcmp(entry->match, match) == 0) {
-           TAILQ_REMOVE(&acl->entries, entry, next);
-           return i;
-       }
+    QTAILQ_FOREACH(entry, &acl->entries, next) {
+        i++;
+        if (strcmp(entry->match, match) == 0) {
+            QTAILQ_REMOVE(&acl->entries, entry, next);
+            return i;
+        }
     }
     return -1;
 }