From patchwork Mon Sep 29 07:32:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard W.M. Jones" X-Patchwork-Id: 394295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 247A31400BE for ; Mon, 29 Sep 2014 17:33:00 +1000 (EST) Received: from localhost ([::1]:34789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYVS6-0001Qj-Av for incoming@patchwork.ozlabs.org; Mon, 29 Sep 2014 03:32:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYVRe-0000kA-L4 for qemu-devel@nongnu.org; Mon, 29 Sep 2014 03:32:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XYVRY-0003OD-Hi for qemu-devel@nongnu.org; Mon, 29 Sep 2014 03:32:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYVRY-0003KR-AU for qemu-devel@nongnu.org; Mon, 29 Sep 2014 03:32:24 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8T7WHjF027120 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 29 Sep 2014 03:32:18 -0400 Received: from choo.home.annexia.org (vpn-232-32.phx2.redhat.com [10.3.232.32]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8T7WG2p025031 for ; Mon, 29 Sep 2014 03:32:17 -0400 From: "Richard W.M. Jones" To: qemu-devel@nongnu.org Date: Mon, 29 Sep 2014 08:32:15 +0100 Message-Id: <1411975935-29511-1-git-send-email-rjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] ssh: Don't crash if either host or path is not specified. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org $ ./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 --- block/ssh.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/ssh.c b/block/ssh.c index cd2fd75..54009c0 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_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")) {