Commit d49d4f7b authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

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.
No related merge requests found
Showing with 7 additions and 2 deletions
+7 -2
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment