[PATCH sandbox 3/9] Fix crash if mount option is not fully specified

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

If the user specified '-m ram:/tmp' instead of '-m ram:/tmp=500M'
the code would reference a NULL pointer. Fix it to return an
error message instead. This fixes a coverity identified issue.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 libvirt-sandbox/libvirt-sandbox-config.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libvirt-sandbox/libvirt-sandbox-config.c b/libvirt-sandbox/libvirt-sandbox-config.c
index 8e8ac65..8eb8d4f 100644
--- a/libvirt-sandbox/libvirt-sandbox-config.c
+++ b/libvirt-sandbox/libvirt-sandbox-config.c
@@ -1224,6 +1224,7 @@ gboolean gvir_sandbox_config_add_mount_strv(GVirSandboxConfig *config,
  * - host-bind:/tmp=/var/lib/sandbox/demo/tmp
  * - host-image:/=/var/lib/sandbox/demo.img
  * - guest-bind:/home=/tmp/home
+ * - ram:/tmp=500M
  */
 gboolean gvir_sandbox_config_add_mount_opts(GVirSandboxConfig *config,
                                             const char *mount,
@@ -1262,13 +1263,16 @@ gboolean gvir_sandbox_config_add_mount_opts(GVirSandboxConfig *config,
         source = tmp + 1;
     }
 
+    if (!tmp) {
+        g_set_error(error, GVIR_SANDBOX_CONFIG_ERROR, 0,
+                    _("Missing mount source string on %s"), mount);
+        return FALSE;
+    }
+
     if (type == GVIR_SANDBOX_TYPE_CONFIG_MOUNT_RAM) {
         gint size;
         gchar *end;
-        gchar *sizestr;
-        *tmp = '\0';
-        sizestr = tmp + 1;
-        size = strtol(sizestr, &end, 10);
+        size = strtol(source, &end, 10);
 
         if (end) {
             if (g_str_equal(end, "KiB") || g_str_equal(end, "K"))
-- 
1.8.3.1

--
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]