From 1dc2a75cb61d4632d2acd8481b4e5476d6093598 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 27 Sep 2022 15:29:56 +0200 Subject: [PATCH] files: before sending data to an external command, decode LF back to NUL (There is no need to recode the NULs back to LFs because the sending of the data happens in a separate process, which then simply disappears.) This fixes https://savannah.gnu.org/bugs/?63106. Bug existed since version 2.9.8, since filtering a buffer or a region through an external command was introduced. --- src/files.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index 0b768b04..1950de30 100644 --- a/src/files.c +++ b/src/files.c @@ -988,7 +988,16 @@ void send_data(const linestruct *line, int fd) /* Send each line, except a final empty line. */ while (line != NULL && (line->next != NULL || line->data[0] != '\0')) { - fprintf(tube, "%s%s", line->data, line->next == NULL ? "" : "\n"); + size_t length = strlen(line->data); + + recode_LF_to_NUL(line->data); + + if (fwrite(line->data, sizeof(char), length, tube) < length) + exit(5); + + if (line->next && putc('\n', tube) == EOF) + exit(6); + line = line->next; }