From 2b48c38be60cf9033761365f40c05f2e6a41a1c4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 5 Oct 2015 15:10:44 +0200 Subject: uudecode: tolerate text input with CR+LF line ends function old new delta read_stduu 265 308 +43 uudecode_main 313 317 +4 Signed-off-by: Denys Vlasenko --- coreutils/uudecode.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'coreutils/uudecode.c') diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index 7aa5c67f2..37b254d30 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c @@ -29,9 +29,19 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U { char *line; - while ((line = xmalloc_fgetline(src_stream)) != NULL) { + for (;;) { int encoded_len, str_len; char *line_ptr, *dst; + size_t line_len; + + line_len = 64 * 1024; + line = xmalloc_fgets_str_len(src_stream, "\n", &line_len); + if (!line) + break; + /* Handle both Unix and MSDOS text, and stray trailing spaces */ + str_len = line_len; + while (--str_len >= 0 && isspace(line[str_len])) + line[str_len] = '\0'; if (strcmp(line, "end") == 0) { return; /* the only non-error exit */ @@ -128,6 +138,7 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv) if (!outname) break; outname++; + trim(outname); /* remove trailing space (and '\r' for DOS text) */ if (!outname[0]) break; } -- cgit v1.2.3