From patchwork Tue Feb 5 13:49:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 10797483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6EA6A13BF for ; Tue, 5 Feb 2019 13:50:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E1162AB85 for ; Tue, 5 Feb 2019 13:50:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51EF52ABCE; Tue, 5 Feb 2019 13:50:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 02E8E2AB85 for ; Tue, 5 Feb 2019 13:50:41 +0000 (UTC) Received: from localhost ([127.0.0.1]:60633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gr17Y-0004NQ-CM for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Feb 2019 08:50:40 -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_Lureau?= 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) 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_Lureau?= , kchamart@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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='blockdev-create job-id="job0 foo" options={"driver":"qcow2","size":16384,"file":{"driver":"file","filename":"foo.qcow2"}}' shlex.split(cmd) ['blockdev-create', 'job-id=job0 foo', 'options={driver:qcow2,size:16384,file:{driver:file,filename:foo.qcow2}}'] Replace with a regexp to split while respecting quoted strings and preserving quotes: re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''', cmd) ['blockdev-create', 'job-id="job0 foo"', 'options={"driver":"qcow2","size":16384,"file":{"driver":"file","filename":"foo.qcow2"}}'] Fixes: fcfab7541 ("qmp-shell: learn to send commands with quoted arguments") Reported-by: Kashyap Chamarthy Signed-off-by: Marc-André 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 class QMPCompleter(list): def complete(self, text, state): @@ -220,7 +220,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): < command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ] """ - cmdargs = shlex.split(cmdline) + cmdargs = re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''', cmdline) # Transactional CLI entry/exit: if cmdargs[0] == 'transaction(':