NetBSD-Bugs archive

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

lib/53682: libedit writes padding, not newline, to terminal when restoring a multi-line history entry



>Number:         53682
>Category:       lib
>Synopsis:       libedit writes padding, not newline, to terminal when restoring a multi-line history entry
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 25 00:40:00 +0000 2018
>Originator:     Jordan Lewis
>Release:        latest
>Organization:
Cockroach Labs
>Environment:
Darwin Termato.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
>Description:
The libedit library mishandles the printing of restored, multi-line history entries. Instead of printing a newline after each line within the history entry, it writes spaces until the edge of the terminal.

This leads to unreadable output when copy-pasting the result of libedit-written output, since all newlines in the restored command are deleted and replaced with padded spaces proportional to the size of the terminal.

See https://github.com/cockroachdb/cockroach/issues/31843 for more details.
>How-To-Repeat:
Compile and run the short test program at the end of this message, press up and enter, then copy-paste the output to a text editor to see what happened.

ACTUAL OUTPUT:

demo (press up to see bug)> this history line has an                                                                   embedded newline
Got input: this history line has an
embedded newline
demo (press up to see bug)>

EXPECTED OUTPUT:

demo (press up to see bug)> this history line has an
embedded newline
Got input: this history line has an
embedded newline
demo (press up to see bug)>

Note that the actual output has no actual newline - just padded spaces

#include <stdio.h>
#include <stdlib.h>
#include <editline/readline.h>

int main(int argc, char** argv) {
  add_history("this history line has an\nembedded newline");
  while (1) {
    char* input = readline("demo (press up to see bug)> ");
    add_history(input);
    printf("Got input: %s\n", input);
    /* free input */
    free(input);
  }
  return 0;
}
>Fix:
No known fix. I took a look at the code, especially refresh.c and the re__copy_and_pad function that I suspect is going wrong, but I couldn't understand what was going on well enough to fix it.



Home | Main Index | Thread Index | Old Index