From nobody Fri May 3 01:14:59 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1549374664798724.5436072897654; Tue, 5 Feb 2019 05:51:04 -0800 (PST) Received: from localhost ([127.0.0.1]:60633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr17l-0004NQ-Rj for importer@patchew.org; Tue, 05 Feb 2019 08:50:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr16c-0003l4-LB for qemu-devel@nongnu.org; Tue, 05 Feb 2019 08:49:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gr16Y-0001RX-V2 for qemu-devel@nongnu.org; Tue, 05 Feb 2019 08:49:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25010) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gr16T-0001Gf-JR for qemu-devel@nongnu.org; Tue, 05 Feb 2019 08:49:36 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 2F3EBC05D404 for ; Tue, 5 Feb 2019 13:49:28 +0000 (UTC) Received: from localhost (ovpn-112-67.ams2.redhat.com [10.36.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B6BB6D881; Tue, 5 Feb 2019 13:49:27 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 5 Feb 2019 14:49:26 +0100 Message-Id: <20190205134926.8312-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 05 Feb 2019 13:49:28 +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] [PATCH] 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: armbru@redhat.com, Cleber Rosa , ehabkost@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , kchamart@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 --- 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 770140772d..813dd68232 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -74,7 +74,7 @@ import sys import os import errno import atexit -import shlex +import re =20 class QMPCompleter(list): def complete(self, text, state): @@ -220,7 +220,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.20.1.98.gecbdaf0899