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

Daniel P. Berrange berrange at redhat.com
Thu Aug 15 15:36:41 UTC 2013


From: "Daniel P. Berrange" <berrange at redhat.com>

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 at redhat.com>
---
 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




More information about the libvir-list mailing list