[PATCHv2 13/27] qemu: reject unknown flags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* src/qemu/qemu_driver.c (qemudOpen, qemuDomainScreenshot)
(qemuDomainXMLFromNative, qemuDomainXMLToNative)
(qemudDomainBlockPeek, qemuCPUCompare, qemuCPUBaseline): Reject
unknown flags.
* src/qemu/qemu_migration.c (qemuMigrationConfirm): Likewise.
(_qemuMigrationCookie, qemuMigrationCookieXMLParse)
(qemuMigrationCookieXMLParseStr, qemuMigrationBakeCookie)
(qemuMigrationEatCookie): Make flags unsigned.
* src/qemu/qemu_domain.h: (qemuDomainDefFormatXML)
(qemuDomainFormatXML): Prefer unsigned flags.
* src/qemu/qemu_domain.c (qemuDomainDefFormatXML)
(qemuDomainFormatXML): Likewise.
(qemuDomainOpenLogHelper, qemuDomainCreateLog): Rename variable.
---
 src/qemu/qemu_domain.c    |   21 +++++++++++----------
 src/qemu/qemu_domain.h    |    4 ++--
 src/qemu/qemu_driver.c    |   30 +++++++++++++++++++++++-------
 src/qemu/qemu_migration.c |   16 +++++++++-------
 4 files changed, 45 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 4b65d87..91be0df 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -703,7 +703,7 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,

 char *qemuDomainDefFormatXML(struct qemud_driver *driver,
                              virDomainDefPtr def,
-                             int flags)
+                             unsigned int flags)
 {
     char *ret = NULL;
     virCPUDefPtr cpu = NULL;
@@ -735,7 +735,7 @@ cleanup:

 char *qemuDomainFormatXML(struct qemud_driver *driver,
                           virDomainObjPtr vm,
-                          int flags)
+                          unsigned int flags)
 {
     virDomainDefPtr def;

@@ -835,7 +835,7 @@ void qemuDomainObjCheckNetTaint(struct qemud_driver *driver,
 static int
 qemuDomainOpenLogHelper(struct qemud_driver *driver,
                         virDomainObjPtr vm,
-                        int flags,
+                        int oflags,
                         mode_t mode)
 {
     char *logfile;
@@ -846,7 +846,7 @@ qemuDomainOpenLogHelper(struct qemud_driver *driver,
         return -1;
     }

-    if ((fd = open(logfile, flags, mode)) < 0) {
+    if ((fd = open(logfile, oflags, mode)) < 0) {
         virReportSystemError(errno, _("failed to create logfile %s"),
                              logfile);
         goto cleanup;
@@ -865,18 +865,19 @@ cleanup:


 int
-qemuDomainCreateLog(struct qemud_driver *driver, virDomainObjPtr vm, bool append)
+qemuDomainCreateLog(struct qemud_driver *driver, virDomainObjPtr vm,
+                    bool append)
 {
-    int flags;
+    int oflags;

-    flags = O_CREAT | O_WRONLY;
+    oflags = O_CREAT | O_WRONLY;
     /* Only logrotate files in /var/log, so only append if running privileged */
     if (driver->privileged || append)
-        flags |= O_APPEND;
+        oflags |= O_APPEND;
     else
-        flags |= O_TRUNC;
+        oflags |= O_TRUNC;

-    return qemuDomainOpenLogHelper(driver, vm, flags, S_IRUSR | S_IWUSR);
+    return qemuDomainOpenLogHelper(driver, vm, oflags, S_IRUSR | S_IWUSR);
 }


diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f282df2..794eef7 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -127,11 +127,11 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,

 char *qemuDomainDefFormatXML(struct qemud_driver *driver,
                              virDomainDefPtr vm,
-                             int flags);
+                             unsigned int flags);

 char *qemuDomainFormatXML(struct qemud_driver *driver,
                           virDomainObjPtr vm,
-                          int flags);
+                          unsigned int flags);

 void qemuDomainObjTaint(struct qemud_driver *driver,
                         virDomainObjPtr obj,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a05a1ee..dd5d918 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -800,8 +800,10 @@ static int qemuDomainSnapshotSetCurrentInactive(virDomainObjPtr vm,

 static virDrvOpenStatus qemudOpen(virConnectPtr conn,
                                   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-                                  unsigned int flags ATTRIBUTE_UNUSED)
+                                  unsigned int flags)
 {
+    virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
     if (conn->uri == NULL) {
         if (qemu_driver == NULL)
             return VIR_DRV_OPEN_DECLINED;
@@ -2685,7 +2687,7 @@ static char *
 qemuDomainScreenshot(virDomainPtr dom,
                      virStreamPtr st,
                      unsigned int screen,
-                     unsigned int flags ATTRIBUTE_UNUSED)
+                     unsigned int flags)
 {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
@@ -2694,6 +2696,8 @@ qemuDomainScreenshot(virDomainPtr dom,
     int tmp_fd = -1;
     char *ret = NULL;

+    virCheckFlags(0, NULL);
+
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
     qemuDriverUnlock(driver);
@@ -3880,11 +3884,14 @@ cleanup:
 static char *qemuDomainXMLFromNative(virConnectPtr conn,
                                      const char *format,
                                      const char *config,
-                                     unsigned int flags ATTRIBUTE_UNUSED) {
+                                     unsigned int flags)
+{
     struct qemud_driver *driver = conn->privateData;
     virDomainDefPtr def = NULL;
     char *xml = NULL;

+    virCheckFlags(0, NULL);
+
     if (STRNEQ(format, QEMU_CONFIG_FORMAT_ARGV)) {
         qemuReportError(VIR_ERR_INVALID_ARG,
                         _("unsupported config type %s"), format);
@@ -3907,7 +3914,8 @@ cleanup:
 static char *qemuDomainXMLToNative(virConnectPtr conn,
                                    const char *format,
                                    const char *xmlData,
-                                   unsigned int flags ATTRIBUTE_UNUSED) {
+                                   unsigned int flags)
+{
     struct qemud_driver *driver = conn->privateData;
     virDomainDefPtr def = NULL;
     virDomainChrSourceDef monConfig;
@@ -3916,6 +3924,8 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
     char *ret = NULL;
     int i;

+    virCheckFlags(0, NULL);
+
     qemuDriverLock(driver);

     if (STRNEQ(format, QEMU_CONFIG_FORMAT_ARGV)) {
@@ -6163,12 +6173,14 @@ qemudDomainBlockPeek (virDomainPtr dom,
                       const char *path,
                       unsigned long long offset, size_t size,
                       void *buffer,
-                      unsigned int flags ATTRIBUTE_UNUSED)
+                      unsigned int flags)
 {
     struct qemud_driver *driver = dom->conn->privateData;
     virDomainObjPtr vm;
     int fd = -1, ret = -1, i;

+    virCheckFlags(0, -1);
+
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
     qemuDriverUnlock(driver);
@@ -7239,11 +7251,13 @@ out:
 static int
 qemuCPUCompare(virConnectPtr conn,
                const char *xmlDesc,
-               unsigned int flags ATTRIBUTE_UNUSED)
+               unsigned int flags)
 {
     struct qemud_driver *driver = conn->privateData;
     int ret = VIR_CPU_COMPARE_ERROR;

+    virCheckFlags(0, VIR_CPU_COMPARE_ERROR);
+
     qemuDriverLock(driver);

     if (!driver->caps || !driver->caps->host.cpu) {
@@ -7263,10 +7277,12 @@ static char *
 qemuCPUBaseline(virConnectPtr conn ATTRIBUTE_UNUSED,
                 const char **xmlCPUs,
                 unsigned int ncpus,
-                unsigned int flags ATTRIBUTE_UNUSED)
+                unsigned int flags)
 {
     char *cpu;

+    virCheckFlags(0, NULL);
+
     cpu = cpuBaselineXML(xmlCPUs, ncpus, NULL, 0);

     return cpu;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 48fc0c0..fcfa828 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -76,8 +76,8 @@ struct _qemuMigrationCookieGraphics {
 typedef struct _qemuMigrationCookie qemuMigrationCookie;
 typedef qemuMigrationCookie *qemuMigrationCookiePtr;
 struct _qemuMigrationCookie {
-    int flags;
-    int flagsMandatory;
+    unsigned int flags;
+    unsigned int flagsMandatory;

     /* Host properties */
     unsigned char localHostuuid[VIR_UUID_BUFLEN];
@@ -446,7 +446,7 @@ error:
 static int
 qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
                             xmlXPathContextPtr ctxt,
-                            int flags)
+                            unsigned int flags)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     char *tmp;
@@ -580,7 +580,7 @@ error:
 static int
 qemuMigrationCookieXMLParseStr(qemuMigrationCookiePtr mig,
                                const char *xml,
-                               int flags)
+                               unsigned int flags)
 {
     xmlDocPtr doc = NULL;
     xmlXPathContextPtr ctxt = NULL;
@@ -614,7 +614,7 @@ qemuMigrationBakeCookie(qemuMigrationCookiePtr mig,
                         virDomainObjPtr dom,
                         char **cookieout,
                         int *cookieoutlen,
-                        int flags)
+                        unsigned int flags)
 {
     if (!cookieout || !cookieoutlen)
         return 0;
@@ -645,7 +645,7 @@ qemuMigrationEatCookie(struct qemud_driver *driver,
                        virDomainObjPtr dom,
                        const char *cookiein,
                        int cookieinlen,
-                       int flags)
+                       unsigned int flags)
 {
     qemuMigrationCookiePtr mig = NULL;

@@ -2605,7 +2605,7 @@ int qemuMigrationConfirm(struct qemud_driver *driver,
                          virDomainObjPtr vm,
                          const char *cookiein,
                          int cookieinlen,
-                         unsigned int flags ATTRIBUTE_UNUSED,
+                         unsigned int flags,
                          int retcode)
 {
     qemuMigrationCookiePtr mig;
@@ -2616,6 +2616,8 @@ int qemuMigrationConfirm(struct qemud_driver *driver,
               driver, conn, vm, NULLSTR(cookiein), cookieinlen,
               flags, retcode);

+    virCheckFlags(0, -1);
+
     if (!(mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen, 0)))
         return -1;

-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]