Skip to contentSkip to conversation

ssh: Don't crash if either host or path is not specified.

PATCH Superseded Richard W.M. Jones 2 participants 2 messages Sep 29, 2014 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ssh: Don't crash if either host or path is not specified.

$ ./qemu-img create -f qcow2 overlay \
    -b 'json: { "file.driver":"ssh",
                "file.host":"localhost",
                "file.host_key_check":"no" }'
qemu-img: qobject/qdict.c:193: qdict_get_obj: Assertion `obj != ((void *)0)' failed.
Aborted

A similar crash also happens if the file.host field is omitted.

https://bugzilla.redhat.com/show_bug.cgi?id=1147343

Bug found and reported by Jun Li.

---
 block/ssh.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
block/ssh.c +10 -0
index cd2fd75..54009c0 100644
@@ -517,6 +517,11 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
     const char *host, *user, *path, *host_key_check;
     int port;
 
+    if (!qdict_haskey(options, "host")) {
+        ret = -EINVAL;
+        error_setg_errno(errp, errno, "No hostname was specified");
+        goto err;
+    }
     host = qdict_get_str(options, "host");
 
     if (qdict_haskey(options, "port")) {
@@ -525,6 +530,11 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
         port = 22;
     }
 
+    if (!qdict_haskey(options, "path")) {
+        ret = -EINVAL;
+        error_setg_errno(errp, errno, "No path was specified");
+        goto err;
+    }
     path = qdict_get_str(options, "path");
 
     if (qdict_haskey(options, "user")) {
Signature · 1 line
2.0.4
#1 lore raw
Quoted 27 lines

Subject: [Qemu-devel] [PATCH] ssh: Don't crash if either host or path is not specified.

$ ./qemu-img create -f qcow2 overlay \
    -b 'json: { "file.driver":"ssh",
                "file.host":"localhost",
                "file.host_key_check":"no" }'
qemu-img: qobject/qdict.c:193: qdict_get_obj: Assertion `obj != ((void *)0)'
failed.
Aborted

A similar crash also happens if the file.host field is omitted.

https://bugzilla.redhat.com/show_bug.cgi?id=1147343

Bug found and reported by Jun Li.

---
 block/ssh.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
block/ssh.c +0 -0
index cd2fd75..54009c0 100644

block/ssh.c static int connect_to_ssh(BDRVSSHState *s, QDict · line 523

Quoted 7 lines
block/ssh.c +3 -0
@@ -517,6 +517,11 @@ static int connect_to_ssh(BDRVSSHState *s, QDict
 *options,
     const char *host, *user, *path, *host_key_check;
     int port;
 
+    if (!qdict_haskey(options, "host")) {
+        ret = -EINVAL;
+        error_setg_errno(errp, errno, "No hostname was specified");

I don't think errno is useful (will be a random value) here. You just need use error_setg(), and return ret directly. :)

block/ssh.c static int connect_to_ssh(BDRVSSHState *s, QDict · line 536

Quoted 13 lines
block/ssh.c +2 -0
+        goto err;
+    }
     host = qdict_get_str(options, "host");
 
     if (qdict_haskey(options, "port")) {
block/ssh.c +3 -0
@@ -525,6 +530,11 @@ static int connect_to_ssh(BDRVSSHState *s, QDict
 *options,
         port = 22;
     }
 
+    if (!qdict_haskey(options, "path")) {
+        ret = -EINVAL;
+        error_setg_errno(errp, errno, "No path was specified");

Here, too.

Quoted 8 lines
block/ssh.c +2 -0
+        goto err;
+    }
     path = qdict_get_str(options, "path");
 
     if (qdict_haskey(options, "user")) {

--
2.0.4

BTW, you'd better CC corresponding maintainer in the next version. You can get the maintainer by "./script/get_maintainer.pl" script.

Best regards,
-Gonglei