NetBSD Problem Report #54279
From www@netbsd.org Thu Jun 6 18:37:09 2019
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 5CA9E7A177
for <gnats-bugs@gnats.NetBSD.org>; Thu, 6 Jun 2019 18:37:09 +0000 (UTC)
Message-Id: <20190606183708.347CB7A1C2@mollari.NetBSD.org>
Date: Thu, 6 Jun 2019 18:37:08 +0000 (UTC)
From: jperkins+netbsd@google.com
Reply-To: jperkins+netbsd@google.com
To: gnats-bugs@NetBSD.org
Subject: Adjacent RL_PROMPT_END_IGNORE/START_IGNORE escapes break
X-Send-Pr-Version: www-1.0
>Number: 54279
>Category: lib
>Synopsis: Adjacent RL_PROMPT_END_IGNORE/START_IGNORE escapes break
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jun 06 18:40:00 +0000 2019
>Last-Modified: Fri Jun 07 15:20:01 +0000 2019
>Originator: Jonathan Perkins
>Release: Sources as of 2019-06-06
>Organization:
Google
>Environment:
>Description:
libedit turns RL_PROMPT_END_IGNORE into RL_PROMPT_START_IGNORE in rl_set_prompt. Because RL_PROMPT_START_IGNORE is an escape character, the double-escape breaks the expected escape behaviors.
This seems to come up in places where people are using APIs to set the prompt. e.g., iPython does some prompt colorization internally, and people sometimes pass in already-colored prompts.
The proposed patch checks for adjacent END/START characters, and remove both in that case, as the "ignore" section doesn't need to stop.
>How-To-Repeat:
Do a call like:
readline("\x01\x1b[0;32m\x02\x01\x1b[0;34m\x02Test:\x01\x1b[0m\x02 ");
(where RL_PROMPT_START_IGNORE is \x01 and RL_PROMPT_END_IGNORE is \x02)
Expected: "Test: " in blue.
Actual: "[0;34m[0m"
>Fix:
--- old/libedit/readline.c
+++ new/libedit/readline.c
@@ -258,8 +258,15 @@ rl_set_prompt(const char *prompt)
if (rl_prompt == NULL)
return -1;
- while ((p = strchr(rl_prompt, RL_PROMPT_END_IGNORE)) != NULL)
- *p = RL_PROMPT_START_IGNORE;
+ while ((p = strchr(rl_prompt, RL_PROMPT_END_IGNORE)) != NULL) {
+ /* Remove adjacent end/start markers to avoid double-escapes. */
+ if (p[1] == RL_PROMPT_START_IGNORE) {
+ memmove(p, p + 2, 1 + strlen(p + 2));
+ } else {
+ *p = RL_PROMPT_START_IGNORE;
+ }
+ }
+
return 0;
}
>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54279 CVS commit: src/lib/libedit
Date: Fri, 7 Jun 2019 11:18:20 -0400
Module Name: src
Committed By: christos
Date: Fri Jun 7 15:18:20 UTC 2019
Modified Files:
src/lib/libedit: readline.c
Log Message:
PR/54279: Jonathan Perkins: Ignore adjacent start/end prompt ignore.
To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/lib/libedit/readline.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
(Contact us)
$NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.