nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit d49d4f7b5604a24e5e724cb03454b6f31b036383
parent 2fbb71d555b74ab9ae0ce222a2c00478efcfaa5d
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Fri, 23 Dec 2016 10:43:15 +0100

history: search items *can* contain newlines -- encoded NUL bytes

Decode 0x0A bytes to 0x00 when saving the search history, and encode
them again when reading the file back in, to prevent nano from hanging
or aborting when encountering 0x00 on a line by itself.

Diffstat:
Msrc/files.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -2961,9 +2961,11 @@ void load_history(void) while ((read = getline(&line, &buf_len, hist)) > 0) { line[--read] = '\0'; - if (read > 0) + if (read > 0) { + /* Encode any embedded NUL as 0x0A. */ + unsunder(line, read); update_history(history, line); - else + } else history = &replace_history; } @@ -2986,6 +2988,9 @@ bool writehist(FILE *hist, const filestruct *head) for (item = head; item != NULL; item = item->next) { size_t length = strlen(item->data); + /* Decode 0x0A bytes as embedded NULs. */ + sunder(item->data); + if (fwrite(item->data, sizeof(char), length, hist) < length) return FALSE; if (putc('\n', hist) == EOF)