From nobody Mon Dec 15 01:57:36 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 1510589214001968.4317639725261; Mon, 13 Nov 2017 08:06:54 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73B7ADCA0D; Mon, 13 Nov 2017 16:06:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 44EF57EE3B; Mon, 13 Nov 2017 16:06:52 +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 12D4114B24; Mon, 13 Nov 2017 16:06:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vADG6i1j016716 for ; Mon, 13 Nov 2017 11:06:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 755D88386A; Mon, 13 Nov 2017 16:06:44 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-194.brq.redhat.com [10.40.204.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id D90798120E for ; Mon, 13 Nov 2017 16:06:43 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 13 Nov 2017 17:06:23 +0100 Message-Id: <32ee33f6817b4d9abb6dd96d7f0f54dea867a951.1510588897.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/12] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Nov 2017 16:06:52 +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 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/vsh.c b/tools/vsh.c index 2a83dc475..3a9941017 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2874,7 +2874,15 @@ vshReadlineParse(const char *text, int state) } } =20 - if (!res) { + if (res) { + if (!rl_completion_quote_character) { + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + virBufferEscapeShell(&buf, res); + VIR_FREE(res); + if (!(res =3D virBufferContentAndReset(&buf))) + goto error; + } + } else { VIR_FREE(sanitized_text); VIR_FREE(ctext); } @@ -2900,6 +2908,16 @@ vshReadlineCompletion(const char *text, return matches; } =20 + +static int +vshReadlineCharIsQuoted(char *line, int index) +{ + return index > 0 && + line[index - 1] =3D=3D '\\' && + !vshReadlineCharIsQuoted(line, index - 1); +} + + # define HISTSIZE_MAX 500000 =20 static int @@ -2924,6 +2942,8 @@ vshReadlineInit(vshControl *ctl) rl_attempted_completion_function =3D vshReadlineCompletion; =20 rl_basic_word_break_characters =3D " \t\n\\`@$><=3D;|&{("; + rl_completer_quote_characters =3D "\"'"; + rl_char_is_quoted_p =3D vshReadlineCharIsQuoted; =20 if (virAsprintf(&histsize_env, "%s_HISTSIZE", ctl->env_prefix) < 0) goto cleanup; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list