From patchwork Thu Jul 4 13:09:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 256895 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D825D2C007B for ; Thu, 4 Jul 2013 23:11:23 +1000 (EST) Received: from localhost ([::1]:60166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UujJh-0006VT-IQ for incoming@patchwork.ozlabs.org; Thu, 04 Jul 2013 09:11:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UujHv-0003vw-FG for qemu-devel@nongnu.org; Thu, 04 Jul 2013 09:09:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UujHr-00006Y-Nk for qemu-devel@nongnu.org; Thu, 04 Jul 2013 09:09:31 -0400 Received: from oxygen.pond.sub.org ([2a01:4f8:121:10e4::3]:36896) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UujHr-00005w-Hu for qemu-devel@nongnu.org; Thu, 04 Jul 2013 09:09:27 -0400 Received: from blackfin.pond.sub.org (p5B32B473.dip0.t-ipconnect.de [91.50.180.115]) by oxygen.pond.sub.org (Postfix) with ESMTPA id A74D09FE48; Thu, 4 Jul 2013 15:09:24 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CEAC5200B4; Thu, 4 Jul 2013 15:09:23 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 4 Jul 2013 15:09:17 +0200 Message-Id: <1372943363-24081-2-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1372943363-24081-1-git-send-email-armbru@redhat.com> References: <1372943363-24081-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:4f8:121:10e4::3 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 1/7] qemu-option: Fix qemu_opts_find() for null id arguments 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 Crashes when the first list member has an ID. Admittedly nonsensical reproducer: $ qemu-system-x86_64 -nodefaults -machine id=foo -machine "" Signed-off-by: Markus Armbruster Reviewed-by: Peter Maydell --- util/qemu-option.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 412c425..2715f27 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -706,16 +706,12 @@ QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id) QemuOpts *opts; QTAILQ_FOREACH(opts, &list->head, next) { - if (!opts->id) { - if (!id) { - return opts; - } - continue; + if (!opts->id && !id) { + return opts; } - if (strcmp(opts->id, id) != 0) { - continue; + if (opts->id && id && !strcmp(opts->id, id)) { + return opts; } - return opts; } return NULL; }