From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937110; cv=none; d=zohomail.com; s=zohoarc; b=XhhA/7WZ+g+GmtcQoG53lTsGQa/vBgXrwB9zOAYjO4y09/DTEuLlPM06uVnUfeYtEiQlK+afJdvAZB8vZ4MIjF/822lE3sSI/jqFLi8ierrWV6UUQHIknFx4i9cOVgQWPnd8rfxCReCDBmYySEFsw7JdrT6ipHCASpiaBMeIn2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937110; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5B5p1uJJ/d3bIFfMcmE8v5AS5z5KTCerzqC9kY8J+Vk=; b=Ccpn9cwr6/BK192HCRdB38IjZfcE6kxjgtTDBqL8MnMWMV28xP+ZyeIbqgWQkbqHfiQHQUYLau9sMbea/cPTf3yu5MCkgb8cPhSz9I/lRBDp2YGxV1I4X+RRksukKBz/1KZFGVUKCgR4dxPLewv3d3GejN5g6u/Nq7HljDLwtpw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586937110746269.86942387361796; Wed, 15 Apr 2020 00:51:50 -0700 (PDT) Received: from localhost ([::1]:45456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcpp-0002Ci-DR for importer@patchew.org; Wed, 15 Apr 2020 03:51:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51127) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnd-0006KG-8k for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnc-0007IY-0b for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:41057 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnb-0007IL-T4 for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-288-1AMbhQZ_O1q1r1mh_ZjIyQ-1; Wed, 15 Apr 2020 03:49:30 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2ECBB18C35A0; Wed, 15 Apr 2020 07:49:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF61D5DA7B; Wed, 15 Apr 2020 07:49:19 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B123711384A9; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5B5p1uJJ/d3bIFfMcmE8v5AS5z5KTCerzqC9kY8J+Vk=; b=XHzBLwDX0D89zaaHb3i4NSoG1FiEnxGfXrYrCdo9RRvtyk1b14WyuvwHisGZWRWwNezMuT Z+27pf9BEyAs+jZJb6O7CT2KKW66apI7m3s0fjyUXelm0QGeC/0ilAvXMAxKJFAJQ1QQCB EqXNnd6qHJmexTd+UpAuHe7jrTHvLu0= X-MC-Unique: 1AMbhQZ_O1q1r1mh_ZjIyQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 1/9] tests-qemu-opts: Cover has_help_option(), qemu_opt_has_help_opt() Date: Wed, 15 Apr 2020 09:49:19 +0200 Message-Id: <20200415074927.19897-2-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The two turn out to be inconsistent for "a,b,,help". Test case marked /* BUG */. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-qemu-opts.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index ef96e84aed..88a3e7bdf4 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -728,6 +728,49 @@ static void test_opts_parse_size(void) qemu_opts_reset(&opts_list_02); } =20 +static void test_has_help_option(void) +{ + static const struct { + const char *params; + /* expected value of has_help_option() */ + bool expect_has_help_option; + /* expected value of qemu_opt_has_help_opt() with implied=3Dfalse = */ + bool expect_opt_has_help_opt; + /* expected value of qemu_opt_has_help_opt() with implied=3Dtrue */ + bool expect_opt_has_help_opt_implied; + } test[] =3D { + { "help", true, true, false }, + { "?", true, true, false }, + { "helpme", false, false, false }, + { "?me", false, false, false }, + { "a,help", true, true, true }, + { "a,?", true, true, true }, + { "a=3D0,help,b", true, true, true }, + { "a=3D0,?,b", true, true, true }, + { "help,b=3D1", true, true, false }, + { "?,b=3D1", true, true, false }, + { "a,b,,help", false /* BUG */, true, true }, + { "a,b,,?", false /* BUG */, true, true }, + }; + int i; + QemuOpts *opts; + + for (i =3D 0; i < ARRAY_SIZE(test); i++) { + g_assert_cmpint(has_help_option(test[i].params), + =3D=3D, test[i].expect_has_help_option); + opts =3D qemu_opts_parse(&opts_list_03, test[i].params, false, + &error_abort); + g_assert_cmpint(qemu_opt_has_help_opt(opts), + =3D=3D, test[i].expect_opt_has_help_opt); + qemu_opts_del(opts); + opts =3D qemu_opts_parse(&opts_list_03, test[i].params, true, + &error_abort); + g_assert_cmpint(qemu_opt_has_help_opt(opts), + =3D=3D, test[i].expect_opt_has_help_opt_implied); + qemu_opts_del(opts); + } +} + static void append_verify_list_01(QemuOptDesc *desc, bool with_overlapping) { int i =3D 0; @@ -990,6 +1033,7 @@ int main(int argc, char *argv[]) g_test_add_func("/qemu-opts/opts_parse/bool", test_opts_parse_bool); g_test_add_func("/qemu-opts/opts_parse/number", test_opts_parse_number= ); g_test_add_func("/qemu-opts/opts_parse/size", test_opts_parse_size); + g_test_add_func("/qemu-opts/has_help_option", test_has_help_option); g_test_add_func("/qemu-opts/append_to_null", test_opts_append_to_null); g_test_add_func("/qemu-opts/append", test_opts_append); g_test_add_func("/qemu-opts/to_qdict/basic", test_opts_to_qdict_basic); --=20 2.21.1 From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937212; cv=none; d=zohomail.com; s=zohoarc; b=ELHJe+2yOedlaTKCQr0TWdpp0JYyMpL4XHX4QYlNZPYPSkYBvuEmEI2Tlohx8IccY+NkhlkP3BF7OKrQTSZUFTTyqP7/G/qDnA2Tum6yXzexz+XZTA1wAG1ArO0wKZmRHyc+wySZQC8lJgm15VC043AsXDWTi3LEHPQoEPvxwhc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937212; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rAIXpbbqraHJ0iUakgmH+v8sgKkK5mv5KVv3fwySK0s=; b=GuHbEoZvRNFjws0xA6CchJD20CGvv6U3Hf667ATPFHOUgsEARlckuFTvAQPZRaMNYdLVX23WMm6YZGFDBDLWuRHx4+s0wd6WMDjo/QVhHmVM12E+h+e7yBHZhUnxUg0ou8J6YN53P34C9FKOGWCFRegWqoK9Osw5aZd1gUfd3TI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586937212340417.75831650448583; Wed, 15 Apr 2020 00:53:32 -0700 (PDT) Received: from localhost ([::1]:45492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcrS-0005LC-VU for importer@patchew.org; Wed, 15 Apr 2020 03:53:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51156) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnd-0006LH-Rl for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnc-0007JG-H3 for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39095 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnc-0007Id-DO for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-317-b77vZgXkMw-cX7Jd00BFhw-1; Wed, 15 Apr 2020 03:49:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 281CE10CE78C; Wed, 15 Apr 2020 07:49:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0D7519C70; Wed, 15 Apr 2020 07:49:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B48AA11358AF; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rAIXpbbqraHJ0iUakgmH+v8sgKkK5mv5KVv3fwySK0s=; b=g3WL7atlsMXB1Bb16v60HrIoFlcM3xHxdZeOaIRM0BBx6AEHwgMwrgJ7KnGoUhLqCxTVWy XbaH0BjYXDwrWILD/FSoVOGEvmZE06wID8s+j9JIV+FUVqvOzh4R41Y1mZoZbvLR7Vt9Yu BRUSg6oKxFdqKf8IupTs+SF8ZTElgig= X-MC-Unique: b77vZgXkMw-cX7Jd00BFhw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 2/9] qemu-options: Factor out get_opt_name_value() helper Date: Wed, 15 Apr 2020 09:49:20 +0200 Message-Id: <20200415074927.19897-3-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The next commits will put it to use. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- util/qemu-option.c | 102 +++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 46 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 97172b5eaa..f08f4bc458 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -805,61 +805,71 @@ void qemu_opts_print(QemuOpts *opts, const char *sepa= rator) } } =20 +static const char *get_opt_name_value(const char *params, + const char *firstname, + char **name, char **value) +{ + const char *p, *pe, *pc; + + pe =3D strchr(params, '=3D'); + pc =3D strchr(params, ','); + + if (!pe || (pc && pc < pe)) { + /* found "foo,more" */ + if (firstname) { + /* implicitly named first option */ + *name =3D g_strdup(firstname); + p =3D get_opt_value(params, value); + } else { + /* option without value, must be a flag */ + p =3D get_opt_name(params, name, ','); + if (strncmp(*name, "no", 2) =3D=3D 0) { + memmove(*name, *name + 2, strlen(*name + 2) + 1); + *value =3D g_strdup("off"); + } else { + *value =3D g_strdup("on"); + } + } + } else { + /* found "foo=3Dbar,more" */ + p =3D get_opt_name(params, name, '=3D'); + assert(*p =3D=3D '=3D'); + p++; + p =3D get_opt_value(p, value); + } + + assert(!*p || *p =3D=3D ','); + if (*p =3D=3D ',') { + p++; + } + return p; +} + static void opts_do_parse(QemuOpts *opts, const char *params, const char *firstname, bool prepend, bool *invalidp, Error **errp) { - char *option =3D NULL; - char *value =3D NULL; - const char *p,*pe,*pc; Error *local_err =3D NULL; + char *option, *value; + const char *p; =20 - for (p =3D params; *p !=3D '\0'; p++) { - pe =3D strchr(p, '=3D'); - pc =3D strchr(p, ','); - if (!pe || (pc && pc < pe)) { - /* found "foo,more" */ - if (p =3D=3D params && firstname) { - /* implicitly named first option */ - option =3D g_strdup(firstname); - p =3D get_opt_value(p, &value); - } else { - /* option without value, probably a flag */ - p =3D get_opt_name(p, &option, ','); - if (strncmp(option, "no", 2) =3D=3D 0) { - memmove(option, option+2, strlen(option+2)+1); - value =3D g_strdup("off"); - } else { - value =3D g_strdup("on"); - } - } - } else { - /* found "foo=3Dbar,more" */ - p =3D get_opt_name(p, &option, '=3D'); - assert(*p =3D=3D '=3D'); - p++; - p =3D get_opt_value(p, &value); - } - if (strcmp(option, "id") !=3D 0) { - /* store and parse */ - opt_set(opts, option, value, prepend, invalidp, &local_err); - value =3D NULL; - if (local_err) { - error_propagate(errp, local_err); - goto cleanup; - } - } - if (*p !=3D ',') { - break; + for (p =3D params; *p;) { + p =3D get_opt_name_value(p, firstname, &option, &value); + firstname =3D NULL; + + if (!strcmp(option, "id")) { + g_free(option); + g_free(value); + continue; } + + opt_set(opts, option, value, prepend, invalidp, &local_err); g_free(option); - g_free(value); - option =3D value =3D NULL; + if (local_err) { + error_propagate(errp, local_err); + return; + } } - - cleanup: - g_free(option); - g_free(value); } =20 /** --=20 2.21.1 From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937063; cv=none; d=zohomail.com; s=zohoarc; b=FI92Rhps1Q9M6aYchd487hhusdiQ853RRUUkglU+u9B1iP0wW1RnECdB+vPcrcKvO6s100GQ1CxSEbE2o35lI/n5wMu3o/92Eqwpccg5IWvFPmSVXORGCqQP/XZByRTUlY+LzLFtEqfTrqIDKMB9d4rWyTIahV2ZPj5zEtwtM4k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937063; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KvuqjXhJLnLeqwthQBgW9+Jz4hAncjgDWrmt3VVcZBA=; b=gKEOIj1JDpFX7iQHsMR7hQhRwp/n9zbxMhN5uYBp73SukZ8yPSzPOn1Wejj9fr6csMbRYGYdCT+8Wre6xa6TPCvyfQjbD0Bnxd3CKmLLtdqC0oIWpmcwbG3cSpUO1IUUDhFs1LtRy0DFDEJLujy+FDXk9FVEAttiUYeJbpwCq8U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586937063796397.17357296375167; Wed, 15 Apr 2020 00:51:03 -0700 (PDT) Received: from localhost ([::1]:45442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcp4-0000WQ-K6 for importer@patchew.org; Wed, 15 Apr 2020 03:51:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51140) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnd-0006Ko-Dt for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnc-0007Iy-7k for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:26808 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnc-0007IQ-3P for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-206-Jl3IJNT2OsqnAgGPhlXnKQ-1; Wed, 15 Apr 2020 03:49:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C86A107ACCC; Wed, 15 Apr 2020 07:49:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03C7460BE2; Wed, 15 Apr 2020 07:49:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B7BC511358B0; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KvuqjXhJLnLeqwthQBgW9+Jz4hAncjgDWrmt3VVcZBA=; b=GCY5+D2gZRGDvXv1EyhCuOC3s/SCGLoftOmck6ae+KTLIY9EIUl2OuQp8kHx8gtGlFGem/ urYuV2mwnhNEE0ygf39k38wijGclTUkASH6OKEBMx3uTK6lvYMw19jDr4S8q8ASV0bEm/9 E7Xv5faHXn1g86qbCKeOACklRuna8e0= X-MC-Unique: Jl3IJNT2OsqnAgGPhlXnKQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 3/9] qemu-option: Fix sloppy recognition of "id=..." after ", , " Date: Wed, 15 Apr 2020 09:49:21 +0200 Message-Id: <20200415074927.19897-4-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- tests/test-qemu-opts.c | 4 ++-- util/qemu-option.c | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index 88a3e7bdf4..8ff97268d8 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -500,10 +500,10 @@ static void test_opts_parse(void) g_assert(!opts); /* TODO Cover .merge_lists =3D true */ =20 - /* Buggy ID recognition */ + /* Buggy ID recognition (fixed) */ opts =3D qemu_opts_parse(&opts_list_03, "x=3D,,id=3Dbar", false, &erro= r_abort); g_assert_cmpuint(opts_count(opts), =3D=3D, 1); - g_assert_cmpstr(qemu_opts_id(opts), =3D=3D, "bar"); /* BUG */ + g_assert(!qemu_opts_id(opts)); g_assert_cmpstr(qemu_opt_get(opts, "x"), =3D=3D, ",id=3Dbar"); =20 /* Anti-social ID */ diff --git a/util/qemu-option.c b/util/qemu-option.c index f08f4bc458..d2956082bd 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -872,6 +872,24 @@ static void opts_do_parse(QemuOpts *opts, const char *= params, } } =20 +static char *opts_parse_id(const char *params) +{ + const char *p; + char *name, *value; + + for (p =3D params; *p;) { + p =3D get_opt_name_value(p, NULL, &name, &value); + if (!strcmp(name, "id")) { + g_free(name); + return value; + } + g_free(name); + g_free(value); + } + + return NULL; +} + /** * Store options parsed from @params into @opts. * If @firstname is non-null, the first key=3Dvalue in @params may omit @@ -889,20 +907,13 @@ static QemuOpts *opts_parse(QemuOptsList *list, const= char *params, bool *invalidp, Error **errp) { const char *firstname; - char *id =3D NULL; - const char *p; + char *id =3D opts_parse_id(params); QemuOpts *opts; Error *local_err =3D NULL; =20 assert(!permit_abbrev || list->implied_opt_name); firstname =3D permit_abbrev ? list->implied_opt_name : NULL; =20 - if (strncmp(params, "id=3D", 3) =3D=3D 0) { - get_opt_value(params + 3, &id); - } else if ((p =3D strstr(params, ",id=3D")) !=3D NULL) { - get_opt_value(p + 4, &id); - } - /* * This code doesn't work for defaults && !list->merge_lists: when * params has no id=3D, and list has an element with !opts->id, it --=20 2.21.1 From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937169; cv=none; d=zohomail.com; s=zohoarc; b=CK1R57X4PgIf+mDQV9xjC0dV2OqEcyM95p7wZk8N/glOSMJQnwY8IBNxxBAe5s6+I6zQPXg3tZ5TnL7Hj4WzqZJQQb7LexpM/S3hJ8ijOsldtoh7kLQtyc7pEL8jQodMFv/ixonvyQjbXcKoeAxrtZmssCkNGn5NnxBbOlNz+vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937169; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J6oDerykG+mwM5kflyJ9nS/gfl92MWMWLRccLiUrxpM=; b=Vc7Mf63yElbNJw4daUH1mlNVKwyHGZy/SCl6bayklj/mbtW3vWeiT7IUoOO3tTCl8/KY87c0hzvWbsjSpmsoiqrmdIF6U5xQhy0zhd4rf5WKimEMVWrqFA9rHglabNmTXl65WnpTxYSO6eBzf5F9inGs8T9ief0FFf8G+vkOZEk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15869371691221002.7953008554667; Wed, 15 Apr 2020 00:52:49 -0700 (PDT) Received: from localhost ([::1]:45480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcql-0004PS-PQ for importer@patchew.org; Wed, 15 Apr 2020 03:52:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51157) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnd-0006LI-Rk for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnc-0007JO-LN for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:24263 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnc-0007J8-Hv for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-373-J-ntK4YSMIaFZT0tavuF5A-1; Wed, 15 Apr 2020 03:49:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F24C8017F3; Wed, 15 Apr 2020 07:49:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04734272AF; Wed, 15 Apr 2020 07:49:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BB21311358B1; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J6oDerykG+mwM5kflyJ9nS/gfl92MWMWLRccLiUrxpM=; b=hz9yrxvB0hdFtxRqTqtQXBjF27Ld5el7HV9QTYPLfIBAo9ZtN4Mumz5UUp1TWlzL38ouP3 FTnEvmR1BtHTN3jPvvfQ/FEDNWyRBuXi6l7iCezXkofs+Ey6TLg067MTbYNSMlg1NEaZ50 tJwmX95Kt99fPolMTcRznYl+Y03poiA= X-MC-Unique: J-ntK4YSMIaFZT0tavuF5A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 4/9] qemu-option: Fix has_help_option()'s sloppy parsing Date: Wed, 15 Apr 2020 09:49:22 +0200 Message-Id: <20200415074927.19897-5-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" has_help_option() uses its own parser. It's inconsistent with qemu_opts_parse(), as demonstrated by test-qemu-opts case /qemu-opts/has_help_option. Fix by reusing the common parser. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-qemu-opts.c | 4 ++-- util/qemu-option.c | 39 +++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index 8ff97268d8..77c944c4aa 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -749,8 +749,8 @@ static void test_has_help_option(void) { "a=3D0,?,b", true, true, true }, { "help,b=3D1", true, true, false }, { "?,b=3D1", true, true, false }, - { "a,b,,help", false /* BUG */, true, true }, - { "a,b,,?", false /* BUG */, true, true }, + { "a,b,,help", true, true, true }, + { "a,b,,?", true, true, true }, }; int i; QemuOpts *opts; diff --git a/util/qemu-option.c b/util/qemu-option.c index d2956082bd..0abf26b61f 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -165,26 +165,6 @@ void parse_option_size(const char *name, const char *v= alue, *ret =3D size; } =20 -bool has_help_option(const char *param) -{ - const char *p =3D param; - bool result =3D false; - - while (*p && !result) { - char *value; - - p =3D get_opt_value(p, &value); - if (*p) { - p++; - } - - result =3D is_help_option(value); - g_free(value); - } - - return result; -} - bool is_valid_option_list(const char *p) { char *value =3D NULL; @@ -890,6 +870,25 @@ static char *opts_parse_id(const char *params) return NULL; } =20 +bool has_help_option(const char *params) +{ + const char *p; + char *name, *value; + bool ret; + + for (p =3D params; *p;) { + p =3D get_opt_name_value(p, NULL, &name, &value); + ret =3D is_help_option(name); + g_free(name); + g_free(value); + if (ret) { + return true; + } + } + + return false; +} + /** * Store options parsed from @params into @opts. * If @firstname is non-null, the first key=3Dvalue in @params may omit --=20 2.21.1 From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937370; cv=none; d=zohomail.com; s=zohoarc; b=E0n8PO+1IfnY+HiXDbn89t1TI7kkTAO2GXozwwgPgS3vFu4Fd3z28hCGRJZomorv+dXtOfPljcP6ogw5Dn6z7l1H6fsK5WKMv+yoMOGNJV2FtpjmHUBjBiqZQ92V96tCWsG6BJr1FNJ01I1yafq4V+ZOmxuwevl8B5ZBwg+hgyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937370; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fiLXMPHz393DyIEaz+0bLZVx3mR3IDR1Y7+PMw6nYOA=; b=BajVYfdXVKbJsRyfSsKadY/IEFGXQtb5NEfK6Vq9buQSQi9/akuSd3yVgQ0MM8MlQNlhOGzlnMaW4W9S+5rjW+wmqP5crerXdjZxFtFaGUVszkHLJgo9upk3mewso+kbru3AY7ot1OZRFgpS6alKvsUi16QxZXvm4/GYQAsTZas= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586937370608187.0140802502051; Wed, 15 Apr 2020 00:56:10 -0700 (PDT) Received: from localhost ([::1]:45532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcty-0008T0-Ja for importer@patchew.org; Wed, 15 Apr 2020 03:56:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51229) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnf-0006Ok-8t for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnd-0007Kh-Le for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:35 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:60444 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnd-0007Jp-Eq for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-pHE-baVuPoSkBosw2_h5ow-1; Wed, 15 Apr 2020 03:49:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BBF810CE782; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 645CE116D95; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BE53311358B2; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fiLXMPHz393DyIEaz+0bLZVx3mR3IDR1Y7+PMw6nYOA=; b=HaBlahKvOpw4CdIJUjUsileoMfsWs0ismawmCZiGUizqXWa25wu1OC9lMdeA9b0nRnWCiD BvpvNyphEvJJPHUGxP2bjhxA/qSckRW5ImYwE05RwVbl+WSuF0K9fWxGL7sDwF7CRZZ5uU pLQP5mwBNu+RzHjDdjMewOeP15m2AvM= X-MC-Unique: pHE-baVuPoSkBosw2_h5ow-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 5/9] test-qemu-opts: Simplify test_has_help_option() after bug fix Date: Wed, 15 Apr 2020 09:49:23 +0200 Message-Id: <20200415074927.19897-6-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- tests/test-qemu-opts.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/tests/test-qemu-opts.c b/tests/test-qemu-opts.c index 77c944c4aa..2a0f42a09b 100644 --- a/tests/test-qemu-opts.c +++ b/tests/test-qemu-opts.c @@ -732,41 +732,39 @@ static void test_has_help_option(void) { static const struct { const char *params; - /* expected value of has_help_option() */ - bool expect_has_help_option; /* expected value of qemu_opt_has_help_opt() with implied=3Dfalse = */ - bool expect_opt_has_help_opt; + bool expect; /* expected value of qemu_opt_has_help_opt() with implied=3Dtrue */ - bool expect_opt_has_help_opt_implied; + bool expect_implied; } test[] =3D { - { "help", true, true, false }, - { "?", true, true, false }, - { "helpme", false, false, false }, - { "?me", false, false, false }, - { "a,help", true, true, true }, - { "a,?", true, true, true }, - { "a=3D0,help,b", true, true, true }, - { "a=3D0,?,b", true, true, true }, - { "help,b=3D1", true, true, false }, - { "?,b=3D1", true, true, false }, - { "a,b,,help", true, true, true }, - { "a,b,,?", true, true, true }, + { "help", true, false }, + { "?", true, false }, + { "helpme", false, false }, + { "?me", false, false }, + { "a,help", true, true }, + { "a,?", true, true }, + { "a=3D0,help,b", true, true }, + { "a=3D0,?,b", true, true }, + { "help,b=3D1", true, false }, + { "?,b=3D1", true, false }, + { "a,b,,help", true, true }, + { "a,b,,?", true, true }, }; int i; QemuOpts *opts; =20 for (i =3D 0; i < ARRAY_SIZE(test); i++) { g_assert_cmpint(has_help_option(test[i].params), - =3D=3D, test[i].expect_has_help_option); + =3D=3D, test[i].expect); opts =3D qemu_opts_parse(&opts_list_03, test[i].params, false, &error_abort); g_assert_cmpint(qemu_opt_has_help_opt(opts), - =3D=3D, test[i].expect_opt_has_help_opt); + =3D=3D, test[i].expect); qemu_opts_del(opts); opts =3D qemu_opts_parse(&opts_list_03, test[i].params, true, &error_abort); g_assert_cmpint(qemu_opt_has_help_opt(opts), - =3D=3D, test[i].expect_opt_has_help_opt_implied); + =3D=3D, test[i].expect_implied); qemu_opts_del(opts); } } --=20 2.21.1 From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937522; cv=none; d=zohomail.com; s=zohoarc; b=bM27uRuQxCMDqhOpeRzkzLu4r+yvMRXhEgBQEWpKWOwMO5wD7dH4OEpYB18lhVc4gjdG7DbmHetnH9P75+gQwTBsZIVR3iQsSLnU36g65f5vyaY7WII2PtIBQ0FtJ3w4EXXyG4vZ+eJDiMfekU9DAG7UOyCVS5NZZgArAWbk658= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937522; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AxYhS6566ynMu6iYQOxJwhg94SejROMl4YRxPGotvqc=; b=Gxzo3yDkoEZnbuVk/4z9BHSeER8OCJ4kEibLywc8uFNWwYp49v7YiqnJiPQXJmiZFTVTwU3j4ubUvoyv2iHvDBtJA4m1PaPA58/j8aAR1V5+D6ee6xkOZ7k7858gSiVCF1Tz5Fod/UCYhg9M8A8GY1I3gPATv5GQ/JrlI75fMtY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586937522569292.60208028261764; Wed, 15 Apr 2020 00:58:42 -0700 (PDT) Received: from localhost ([::1]:45582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcwT-0004Vc-9o for importer@patchew.org; Wed, 15 Apr 2020 03:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51239) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnf-0006PF-Fq for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnd-0007Kx-QH for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:35 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:58533 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnd-0007KG-KY for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-QW6mK9fkPD-_F0BW9hHWuA-1; Wed, 15 Apr 2020 03:49:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A84E38018A9; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 64689116D96; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C1A9E11358B3; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AxYhS6566ynMu6iYQOxJwhg94SejROMl4YRxPGotvqc=; b=ZPbKrBGwsBL8ljZVEf8rSP6pIFl2+2LjK+wOJsGfuaT7BoNrnnUaSKHNbF9m1VxDWxbedM hNEA/LAwp5ICntDeibdtTUdkARGB6ptg3sUK3k4M656G7kew0wMtBPn8Q6sZo8HmiBnlAS m93oM625A7ACxiqi68nfc3uCSwlcem0= X-MC-Unique: QW6mK9fkPD-_F0BW9hHWuA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 6/9] qemu-option: Avoid has_help_option() in qemu_opts_parse_noisily() Date: Wed, 15 Apr 2020 09:49:24 +0200 Message-Id: <20200415074927.19897-7-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When opts_parse() sets @invalidp to true, qemu_opts_parse_noisily() uses has_help_option() to decide whether to print help. This parses the input string a second time. Easy to avoid: replace @invalidp by @help_wanted. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- util/qemu-option.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/util/qemu-option.c b/util/qemu-option.c index 0abf26b61f..2d0d24ee27 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -519,7 +519,7 @@ int qemu_opt_unset(QemuOpts *opts, const char *name) } =20 static void opt_set(QemuOpts *opts, const char *name, char *value, - bool prepend, bool *invalidp, Error **errp) + bool prepend, bool *help_wanted, Error **errp) { QemuOpt *opt; const QemuOptDesc *desc; @@ -529,8 +529,8 @@ static void opt_set(QemuOpts *opts, const char *name, c= har *value, if (!desc && !opts_accepts_any(opts)) { g_free(value); error_setg(errp, QERR_INVALID_PARAMETER, name); - if (invalidp) { - *invalidp =3D true; + if (help_wanted && is_help_option(name)) { + *help_wanted =3D true; } return; } @@ -827,7 +827,7 @@ static const char *get_opt_name_value(const char *param= s, =20 static void opts_do_parse(QemuOpts *opts, const char *params, const char *firstname, bool prepend, - bool *invalidp, Error **errp) + bool *help_wanted, Error **errp) { Error *local_err =3D NULL; char *option, *value; @@ -843,7 +843,7 @@ static void opts_do_parse(QemuOpts *opts, const char *p= arams, continue; } =20 - opt_set(opts, option, value, prepend, invalidp, &local_err); + opt_set(opts, option, value, prepend, help_wanted, &local_err); g_free(option); if (local_err) { error_propagate(errp, local_err); @@ -903,7 +903,7 @@ void qemu_opts_do_parse(QemuOpts *opts, const char *par= ams, =20 static QemuOpts *opts_parse(QemuOptsList *list, const char *params, bool permit_abbrev, bool defaults, - bool *invalidp, Error **errp) + bool *help_wanted, Error **errp) { const char *firstname; char *id =3D opts_parse_id(params); @@ -928,7 +928,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const c= har *params, return NULL; } =20 - opts_do_parse(opts, params, firstname, defaults, invalidp, &local_err); + opts_do_parse(opts, params, firstname, defaults, help_wanted, &local_e= rr); if (local_err) { error_propagate(errp, local_err); qemu_opts_del(opts); @@ -964,11 +964,11 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list,= const char *params, { Error *err =3D NULL; QemuOpts *opts; - bool invalidp =3D false; + bool help_wanted =3D false; =20 - opts =3D opts_parse(list, params, permit_abbrev, false, &invalidp, &er= r); + opts =3D opts_parse(list, params, permit_abbrev, false, &help_wanted, = &err); if (err) { - if (invalidp && has_help_option(params)) { + if (help_wanted) { qemu_opts_print_help(list, true); error_free(err); } else { --=20 2.21.1 From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937454; cv=none; d=zohomail.com; s=zohoarc; b=TuKc/kv4kf3aRlpLDKW46p+SU3ZSgZ1GONEZ0uQqRUsCY/IffRnwotyG095rg/ObnLCWWraxZAv/W37wa6LrAjmzxmieyOGxksg00CQPq34fHzEusXcWUNcD3P6awkugnd40+ajyzKM9+QvOC6kyI0d8hvQ+vm/f8u1XCE2CSyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937454; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=apeeM7s/Me0ShiEgPJBP2dbh22rv4ahsU5BowSbT83U=; b=Z2HFNCUzR9cD3tLrwEzkaRjx4vY0+FJf0nPT5E5E+i8bX2vd5r9Gha2tFKKkwKVDnyafpWzPofp1i+gGMbf5ariqjVjR1yek1AsThjUOcXym7leCwOtVHEmEGalTigOhORtpSko6ftXT40K+ZCNuH+VRVACAUQxvRremWnGKaHk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586937454464376.12444252406124; Wed, 15 Apr 2020 00:57:34 -0700 (PDT) Received: from localhost ([::1]:45564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcvN-0002pE-6k for importer@patchew.org; Wed, 15 Apr 2020 03:57:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51236) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnf-0006PB-GK for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnd-0007L4-Qw for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:35 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:20965 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnd-0007KC-Lm for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-218-d6G9fokbNimV-Va6PpK2Mw-1; Wed, 15 Apr 2020 03:49:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A993B10CE783; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A83BA0983; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C4F9811358B7; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=apeeM7s/Me0ShiEgPJBP2dbh22rv4ahsU5BowSbT83U=; b=FOJfVF1JN9kcBOFO9N6axD0eTbeA4YDYAE6uPu99FeLZxrHSBo0WTZSzo/B9yTnUxY6jau RbFfhXjfUK8TXslw5Sp1gTLUGNUqaSggT9tgSL2Jr+nE+F859ykXCtVrWiUYprH/2THrrV SkteINtO3dVMnsgXSbxsrjR9vHq2I0E= X-MC-Unique: d6G9fokbNimV-Va6PpK2Mw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 7/9] qemu-img: Factor out accumulate_options() helper Date: Wed, 15 Apr 2020 09:49:25 +0200 Message-Id: <20200415074927.19897-8-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- qemu-img.c | 59 +++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 821cbf610e..d36b21b758 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -223,6 +223,25 @@ static bool qemu_img_object_print_help(const char *typ= e, QemuOpts *opts) return true; } =20 +static int accumulate_options(char **options, char *optarg) +{ + char *new_options; + + if (!is_valid_option_list(optarg)) { + error_report("Invalid option list: %s", optarg); + return -1; + } + + if (!*options) { + *options =3D g_strdup(optarg); + } else { + new_options =3D g_strdup_printf("%s,%s", *options, optarg); + g_free(*options); + *options =3D new_options; + } + return 0; +} + static QemuOptsList qemu_source_opts =3D { .name =3D "source", .implied_opt_name =3D "file", @@ -482,17 +501,9 @@ static int img_create(int argc, char **argv) fmt =3D optarg; break; case 'o': - if (!is_valid_option_list(optarg)) { - error_report("Invalid option list: %s", optarg); + if (accumulate_options(&options, optarg) < 0) { goto fail; } - if (!options) { - options =3D g_strdup(optarg); - } else { - char *old_options =3D options; - options =3D g_strdup_printf("%s,%s", options, optarg); - g_free(old_options); - } break; case 'q': quiet =3D true; @@ -2127,17 +2138,9 @@ static int img_convert(int argc, char **argv) s.compressed =3D true; break; case 'o': - if (!is_valid_option_list(optarg)) { - error_report("Invalid option list: %s", optarg); + if (accumulate_options(&options, optarg) < 0) { goto fail_getopt; } - if (!options) { - options =3D g_strdup(optarg); - } else { - char *old_options =3D options; - options =3D g_strdup_printf("%s,%s", options, optarg); - g_free(old_options); - } break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { @@ -3953,18 +3956,10 @@ static int img_amend(int argc, char **argv) help(); break; case 'o': - if (!is_valid_option_list(optarg)) { - error_report("Invalid option list: %s", optarg); + if (accumulate_options(&options, optarg) < 0) { ret =3D -1; goto out_no_progress; } - if (!options) { - options =3D g_strdup(optarg); - } else { - char *old_options =3D options; - options =3D g_strdup_printf("%s,%s", options, optarg); - g_free(old_options); - } break; case 'f': fmt =3D optarg; @@ -4855,17 +4850,9 @@ static int img_measure(int argc, char **argv) out_fmt =3D optarg; break; case 'o': - if (!is_valid_option_list(optarg)) { - error_report("Invalid option list: %s", optarg); + if (accumulate_options(&options, optarg) < 0) { goto out; } - if (!options) { - options =3D g_strdup(optarg); - } else { - char *old_options =3D options; - options =3D g_strdup_printf("%s,%s", options, optarg); - g_free(old_options); - } break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { --=20 2.21.1 From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937589; cv=none; d=zohomail.com; s=zohoarc; b=QWyqvLMVzrTrI9cppI+7sYgsMesYSnAVtLObXpGRQJHW9ZVKcc+vKLJeit9ov0DBM262Kz7fCEOcJoHs9phEWAyfWKqir1wzLIvaZ4+1uZ0Xy61/vZ1FlS6EvWJSMXDeGaI09RphtokchJu6Na+zV4UMx8GBrFKJMbJyM1cdnLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937589; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=w4/aCNwhpA9m3Y65zS8cEH4smCxfFNnQD2MenRfIuZ0=; b=l2kTTU6HII2iV3JMgqKIXc6bACLx+hkjQZvt3vrsXlk576gZ8EMpJRjHd5lN9EJm44xdLShPoScGr570NNEU8wlJHjxTdky+wfnKgusoNMpcICz1RNHVOXRjGS/Akb1rvEfM94cJJPLVmgyCkM15MTTPotU8asxOsX2NkhcHiI0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586937589247835.8349980257002; Wed, 15 Apr 2020 00:59:49 -0700 (PDT) Received: from localhost ([::1]:45598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcxY-00063m-1A for importer@patchew.org; Wed, 15 Apr 2020 03:59:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51243) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnf-0006Pe-Kx for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnd-0007LJ-Sj for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:35 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:53989 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnd-0007KS-NB for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-bo95N2rdM3KrbxLdV2EKCQ-1; Wed, 15 Apr 2020 03:49:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B89AE8018AB; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A56B9F9B6; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C838511358BB; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w4/aCNwhpA9m3Y65zS8cEH4smCxfFNnQD2MenRfIuZ0=; b=MgnNG0qcjGcaWBgFJ+wodoLTpRvQ/htL5OtELYmzYyPJA+fZM/gzMOtFIXkNDiw+/K27aB 4kI/MCmPWeU7gswnZ/MfJsAV2LHmRM/Z97LUHb6OjzxDtMoG2AHg1BERNmvAn6StYmjRAL FIq4WiNCa2BAfkqKnZaGPWpvcPMrMk0= X-MC-Unique: bo95N2rdM3KrbxLdV2EKCQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 8/9] qemu-img: Move is_valid_option_list() to qemu-img.c and rewrite Date: Wed, 15 Apr 2020 09:49:26 +0200 Message-Id: <20200415074927.19897-9-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" is_valid_option_list()'s purpose is ensuring qemu-img.c's can safely join multiple parameter strings separated by ',' like this: g_strdup_printf("%s,%s", params1, params2); How it does that is anything but obvious. A close reading of the code reveals that it fails exactly when its argument starts with ',' or ends with an odd number of ','. Makes sense, actually, because when the argument starts with ',', a separating ',' preceding it would get escaped, and when it ends with an odd number of ',', a separating ',' following it would get escaped. Move it to qemu-img.c and rewrite it the obvious way. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/option.h | 1 - qemu-img.c | 26 ++++++++++++++++++++++++++ util/qemu-option.c | 22 ---------------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/include/qemu/option.h b/include/qemu/option.h index 844587cab3..eb4097889d 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -33,7 +33,6 @@ const char *get_opt_value(const char *p, char **value); void parse_option_size(const char *name, const char *value, uint64_t *ret, Error **errp); bool has_help_option(const char *param); -bool is_valid_option_list(const char *param); =20 enum QemuOptType { QEMU_OPT_STRING =3D 0, /* no parsing (use string as-is) = */ diff --git a/qemu-img.c b/qemu-img.c index d36b21b758..cc51db7ed4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -223,6 +223,32 @@ static bool qemu_img_object_print_help(const char *typ= e, QemuOpts *opts) return true; } =20 +/* + * Is @optarg safe for accumulate_options()? + * It is when multiple of them can be joined together separated by ','. + * To make that work, @optarg must not start with ',' (or else a + * separating ',' preceding it gets escaped), and it must not end with + * an odd number of ',' (or else a separating ',' following it gets + * escaped). + */ +static bool is_valid_option_list(const char *optarg) +{ + size_t len =3D strlen(optarg); + size_t i; + + if (optarg[0] =3D=3D ',') { + return false; + } + + for (i =3D len; i > 0 && optarg[i - 1] =3D=3D ','; i--) { + } + if ((len - i) % 2) { + return false; + } + + return true; +} + static int accumulate_options(char **options, char *optarg) { char *new_options; diff --git a/util/qemu-option.c b/util/qemu-option.c index 2d0d24ee27..9542988183 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -165,28 +165,6 @@ void parse_option_size(const char *name, const char *v= alue, *ret =3D size; } =20 -bool is_valid_option_list(const char *p) -{ - char *value =3D NULL; - bool result =3D false; - - while (*p) { - p =3D get_opt_value(p, &value); - if ((*p && !*++p) || - (!*value || *value =3D=3D ',')) { - goto out; - } - - g_free(value); - value =3D NULL; - } - - result =3D true; -out: - g_free(value); - return result; -} - static const char *opt_type_to_string(enum QemuOptType type) { switch (type) { --=20 2.21.1 From nobody Sun May 19 03:38:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586937134; cv=none; d=zohomail.com; s=zohoarc; b=edIV17PoQWKw3z0Sj6J0/16OysJsJiT2GrodQQvBAI/C0sUXpGaK5wJaAYBZrOkz332hXJ5uNwoD0TzSlAzlSkDuOs3vJuOEN0fobbaPcRrEpBkaVolJ9bqK3Jqr9AfZHHnzhtS+0URb9BvU6I7+Ev3WdkeL51PD9QmHRC9Rwik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586937134; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZTXu9VOC5cjy/LHpJSbxX3yw8P34uUaNspmSlmDPxBQ=; b=Qc3GShA9h71XqB4OZ909t8wwS4GXC5R9OUPwlI15gvWhoiyo1VZkXEuJoD+sm+/2kUEq6OSF8XBGr4C/9QM7T+WvchzvEW58tSm0I0wDwn1SVrEoF55XoAabiJUpwB8RViNTJ99SyiqYcGqGsbf7dDRyHjtr0IYRtIkMJETJ4xI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1586937134517456.57618047001927; Wed, 15 Apr 2020 00:52:14 -0700 (PDT) Received: from localhost ([::1]:45466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcqC-00036Z-9v for importer@patchew.org; Wed, 15 Apr 2020 03:52:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51231) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOcnf-0006Oo-9p for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOcnd-0007LQ-TX for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:35 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32509 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jOcnd-0007KP-Oc for qemu-devel@nongnu.org; Wed, 15 Apr 2020 03:49:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-349-njc0c8RrP3GEx9EmSsVteg-1; Wed, 15 Apr 2020 03:49:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B206018C35A7; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-113-20.ams2.redhat.com [10.36.113.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C79119C70; Wed, 15 Apr 2020 07:49:30 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CB6671132C38; Wed, 15 Apr 2020 09:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586936973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZTXu9VOC5cjy/LHpJSbxX3yw8P34uUaNspmSlmDPxBQ=; b=RGLB6+Oz6TiDzDGqR1ayYMTih0aOGI/41U6Lrn2iFIlTbIo7lDOXTMR2uhrKVBl53qke6S 4nrF0TjZBmwd8nM934IRbzgKA/mLn2Dj+7wwpZ81VUYWOjCQbQm2R8MUZD9KmxAVOq3W44 Aks2TG+bMJnD5z8v92tH2cSoJ1+VOhU= X-MC-Unique: njc0c8RrP3GEx9EmSsVteg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH v2 for-5.1 9/9] qemu-img: Reject broken -o "" Date: Wed, 15 Apr 2020 09:49:27 +0200 Message-Id: <20200415074927.19897-10-armbru@redhat.com> In-Reply-To: <20200415074927.19897-1-armbru@redhat.com> References: <20200415074927.19897-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qemu-img create, convert, amend, and measure use accumulate_options() to merge multiple -o options. This is broken for -o "": $ qemu-img create -f qcow2 -o backing_file=3Da -o "" -o backing_fmt=3Dr= aw,size=3D1M new.qcow2 qemu-img: warning: Could not verify backing image. This may become an e= rror in future versions. Could not open 'a,backing_fmt=3Draw': No such file or directory Formatting 'new.qcow2', fmt=3Dqcow2 size=3D1048576 backing_file=3Da,,ba= cking_fmt=3Draw cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 $ qemu-img info new.qcow2 image: new.qcow2 file format: qcow2 virtual size: 1 MiB (1048576 bytes) disk size: 196 KiB cluster_size: 65536 --> backing file: a,backing_fmt=3Draw Format specific information: compat: 1.1 lazy refcounts: false refcount bits: 16 corrupt: false Merging these three -o the obvious way is wrong, because it results in an unwanted ',' escape: backing_file=3Da,,backing_fmt=3Draw,size=3D1M ~~ We could silently drop -o "", but Kevin asked me to reject it instead. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qemu-img.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index cc51db7ed4..a2369766f0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -229,14 +229,16 @@ static bool qemu_img_object_print_help(const char *ty= pe, QemuOpts *opts) * To make that work, @optarg must not start with ',' (or else a * separating ',' preceding it gets escaped), and it must not end with * an odd number of ',' (or else a separating ',' following it gets - * escaped). + * escaped), or be empty (or else a separating ',' preceding it can + * escape a separating ',' following it). + *=20 */ static bool is_valid_option_list(const char *optarg) { size_t len =3D strlen(optarg); size_t i; =20 - if (optarg[0] =3D=3D ',') { + if (!optarg[0] || optarg[0] =3D=3D ',') { return false; } =20 --=20 2.21.1