NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/54279: Adjacent RL_PROMPT_END_IGNORE/START_IGNORE escapes break



>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
>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;
 }



Home | Main Index | Thread Index | Old Index