diff options
author | Natanael Copa | 2021-01-22 08:35:55 +0100 |
---|---|---|
committer | Denys Vlasenko | 2021-02-23 12:59:29 +0100 |
commit | e880c9c100028e6b0e805d4637139c67aea83748 (patch) | |
tree | d521d1378a6782ca6f6a3c53fbcc7df05630454f /coreutils | |
parent | 760b627e2ac6aedbf604040951280eaaf75939a8 (diff) | |
download | busybox-e880c9c100028e6b0e805d4637139c67aea83748.zip busybox-e880c9c100028e6b0e805d4637139c67aea83748.tar.gz |
echo: do not assume that free() leaves errno unmodified
musl libc's mallocng free() may modify errno if kernel does not support
MADV_FREE which causes echo to echo with error when it shouldn't.
Future versions of POSIX[1] will require that free() leaves errno
unmodified but til then, do not rely free() implementation.
Should fix downstream issues:
https://github.com/alpinelinux/docker-alpine/issues/134
https://gitlab.alpinelinux.org/alpine/aports/-/issues/12311
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/echo.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/coreutils/echo.c b/coreutils/echo.c index b382889..61ba060 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c @@ -97,6 +97,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv) #else char nflag = 1; char eflag = 0; + int err; while ((arg = *++argv) != NULL) { char n, e; @@ -185,13 +186,12 @@ int echo_main(int argc UNUSED_PARAM, char **argv) do_write: /* Careful to error out on partial writes too (think ENOSPC!) */ errno = 0; - /*r =*/ full_write(STDOUT_FILENO, buffer, out - buffer); - free(buffer); - if (/*WRONG:r < 0*/ errno) { + err = full_write(STDOUT_FILENO, buffer, out - buffer) != out - buffer; + if (err) { bb_simple_perror_msg(bb_msg_write_error); - return 1; } - return 0; + free(buffer); + return err; } /* |