Skip to contentSkip to conversation

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

PATCH Applied Richard W.M. Jones 3 participants 3 messages Sep 29, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v2 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..35f143d 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(errp, "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(errp, "No path was specified");
+        goto err;
+    }
     path = qdict_get_str(options, "path");
 
     if (qdict_haskey(options, "user")) {
Signature · 1 line
2.0.4
Reviewed-by on v2 1/1
#1 lore raw
Quoted 17 lines

-----Original Message-----
From: Richard W.M. Jones [mailto:[email protected]]
Sent: Monday, September 29, 2014 4:06 PM
To: [email protected]
Cc: Gonglei (Arei)
Subject: [PATCH v2] 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.

Quoted 9 lines

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(+)

Cc'ing Stefan and Kevin.

You can add the change log between v1 and v2.

Anyway, looks good to me, so

Best regards,
-Gonglei

#2 lore raw
In reply to Richard W.M. Jones
Quoted 9 lines · Richard W.M. Jones
$ ./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.

Quoted 8 lines

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(+)

Please CC Kevin Wolf and me on block patches.

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan