From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XaVt1-0005I9-9X for qemu-devel@nongnu.org; Sat, 04 Oct 2014 16:25:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XaVsw-0004Im-Ca for qemu-devel@nongnu.org; Sat, 04 Oct 2014 16:25:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XaVsw-0004If-4R for qemu-devel@nongnu.org; Sat, 04 Oct 2014 16:24:58 -0400 From: Stefan Hajnoczi Date: Sat, 4 Oct 2014 21:24:28 +0100 Message-Id: <1412454289-1789-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1412454289-1789-1-git-send-email-stefanha@redhat.com> References: <1412454289-1789-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 02/23] ssh: Don't crash if either host or path is not specified. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell From: "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. https://bugzilla.redhat.com/show_bug.cgi?id=1147343 Bug found and reported by Jun Li. Signed-off-by: Richard W.M. Jones Reviewed-by: Gonglei Signed-off-by: Stefan Hajnoczi --- block/ssh.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/ssh.c b/block/ssh.c index cf43bc0..f466cbf 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -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")) { -- 1.9.3