commit 1dc2a75cb61d4632d2acd8481b4e5476d6093598
parent 8d7b716ea77a118a1ad4e4c28a2e879fd58a2d6b
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 27 Sep 2022 15:29:56 +0200
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.
Diffstat:
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git 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;
}