From nobody Thu May 15 02:39:15 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1514913158713579.709423994741; Tue, 2 Jan 2018 09:12:38 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 5869F4901B; Tue, 2 Jan 2018 17:12:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3017B60BE2; Tue, 2 Jan 2018 17:12:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EB329180474F; Tue, 2 Jan 2018 17:12:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w02HCWMr003105 for ; Tue, 2 Jan 2018 12:12:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id B702A171BE; Tue, 2 Jan 2018 17:12:32 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-45.brq.redhat.com [10.40.204.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29E115C3F8 for ; Tue, 2 Jan 2018 17:12:31 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 2 Jan 2018 18:11:59 +0100 Message-Id: <99f42cc7c98de7be64940caa7ba1d05896b27ecd.1514911024.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/18] vshReadlineParse: Escape returned results if needed X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 02 Jan 2018 17:12:37 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When returning a string that needs escaping there are two scenarios that can happen. Firstly, user already started the string with a quote (or double quote) in which case we don't need to do anything - readline takes care of that. However, if they haven't typed anything yet, we need to escape the string ourselves. Signed-off-by: Michal Privoznik --- tools/vsh.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/vsh.c b/tools/vsh.c index c3423d6e3..bcabf4231 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2735,6 +2735,14 @@ vshReadlineParse(const char *text, int state) res =3D vshReadlineOptionsGenerator(text, state, cmd); } =20 + if (res && + !rl_completion_quote_character) { + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + virBufferEscapeShell(&buf, res); + VIR_FREE(res); + res =3D virBufferContentAndReset(&buf); + } + if (!res) { vshCommandFree(partial); partial =3D NULL; @@ -2754,6 +2762,16 @@ vshReadlineCompletion(const char *text, return matches; } =20 + +static int +vshReadlineCharIsQuoted(char *line, int idx) +{ + return idx > 0 && + line[idx - 1] =3D=3D '\\' && + !vshReadlineCharIsQuoted(line, idx - 1); +} + + # define HISTSIZE_MAX 500000 =20 static int @@ -2765,6 +2783,7 @@ vshReadlineInit(vshControl *ctl) char *histsize_env =3D NULL; const char *histsize_str =3D NULL; const char *break_characters =3D " \t\n\\`@$><=3D;|&{("; + const char *quote_characters =3D "\"'"; =20 /* Opaque data for autocomplete callbacks. */ autoCompleteOpaque =3D ctl; @@ -2788,6 +2807,14 @@ vshReadlineInit(vshControl *ctl) rl_basic_word_break_characters =3D (char *) break_characters; # endif =20 +# if defined(RL_READLINE_VERSION) && RL_READLINE_VERSION > 0x0402 + rl_completer_quote_characters =3D quote_characters; + rl_char_is_quoted_p =3D vshReadlineCharIsQuoted; +# else + rl_completer_quote_characters =3D (char *) quote_characters; + rl_char_is_quoted_p =3D (Function *) vshReadlineCharIsQuoted; +# endif + if (virAsprintf(&histsize_env, "%s_HISTSIZE", ctl->env_prefix) < 0) goto cleanup; =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list