From nobody Wed May 8 22:59:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; spf=pass (zoho.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 Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552357133047401.1504472160891; Mon, 11 Mar 2019 19:18:53 -0700 (PDT) Received: from localhost ([127.0.0.1]:43657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3X07-00073p-O4 for importer@patchew.org; Mon, 11 Mar 2019 22:18:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3WyZ-0006PX-NC for qemu-devel@nongnu.org; Mon, 11 Mar 2019 22:17:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3WyY-0007Rd-SS for qemu-devel@nongnu.org; Mon, 11 Mar 2019 22:17:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32966) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h3WyY-0007RV-LG for qemu-devel@nongnu.org; Mon, 11 Mar 2019 22:17:06 -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 mx1.redhat.com (Postfix) with ESMTPS id CA6A266970; Tue, 12 Mar 2019 02:17:05 +0000 (UTC) Received: from localhost (ovpn-116-76.gru2.redhat.com [10.97.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D4F25DA27; Tue, 12 Mar 2019 02:17:03 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org, Cleber Rosa Date: Mon, 11 Mar 2019 23:16:59 -0300 Message-Id: <20190312021659.24197-2-ehabkost@redhat.com> In-Reply-To: <20190312021659.24197-1-ehabkost@redhat.com> References: <20190312021659.24197-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 12 Mar 2019 02:17:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/1] qmp-shell: fix nested json regression X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Commit fcfab7541 ("qmp-shell: learn to send commands with quoted arguments") introduces the usage of Python 'shlex' to handle quoted arguments, but it accidentally broke generation of nested JSON structs. shlex drops quotes, which breaks parsing of the nested struct. cmd=3D'blockdev-create job-id=3D"job0 foo" options=3D{"driver":"qcow2","siz= e":16384,"file":{"driver":"file","filename":"foo.qcow2"}}' shlex.split(cmd) ['blockdev-create', 'job-id=3Djob0 foo', 'options=3D{driver:qcow2,size:16384,file:{driver:file,filename:foo.qcow2}}= '] Replace with a regexp to split while respecting quoted strings and preservi= ng quotes: re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''', cmd) ['blockdev-create', 'job-id=3D"job0 foo"', 'options=3D{"driver":"qcow2","size":16384,"file":{"driver":"file","filenam= e":"foo.qcow2"}}'] Fixes: fcfab7541 ("qmp-shell: learn to send commands with quoted arguments") Reported-by: Kashyap Chamarthy Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20190205134926.8312-1-marcandre.lureau@redhat.com> Tested-by: Kashyap Chamarthy Signed-off-by: Eduardo Habkost --- scripts/qmp/qmp-shell | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 9fec46e2ed..7776c7b141 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -73,7 +73,7 @@ import sys import os import errno import atexit -import shlex +import re =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) from qemu import qmp @@ -222,7 +222,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): =20 < command-name > [ arg-name1=3Darg1 ] ... [ arg-nameN=3DargN ] """ - cmdargs =3D shlex.split(cmdline) + cmdargs =3D re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^']= )*')+''', cmdline) =20 # Transactional CLI entry/exit: if cmdargs[0] =3D=3D 'transaction(': --=20 2.18.0.rc1.1.g3f1ff2140