diff options
author | Manuel Novoa III | 2004-05-26 15:21:19 +0000 |
---|---|---|
committer | Manuel Novoa III | 2004-05-26 15:21:19 +0000 |
commit | d709743b09a456f4550ad0b06dca89dc41a19e60 (patch) | |
tree | 994819fb891500254f5b5780c384b7cc075c9610 /coreutils | |
parent | a6f6a95ba45e094bbee6fd0895925a992e4a29cd (diff) | |
download | busybox-d709743b09a456f4550ad0b06dca89dc41a19e60.zip busybox-d709743b09a456f4550ad0b06dca89dc41a19e60.tar.gz |
If read were to return with an error, bad things would happen. Fix it.
Also, make sure read errors are reflected in the applet exit code.
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/tee.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/coreutils/tee.c b/coreutils/tee.c index 6ec1d6d..ba2e10f 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c @@ -38,7 +38,7 @@ int tee_main(int argc, char **argv) int flags; int retval = EXIT_SUCCESS; #ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO - size_t c; + ssize_t c; RESERVE_CONFIG_BUFFER(buf, BUFSIZ); #else int c; @@ -78,12 +78,16 @@ int tee_main(int argc, char **argv) *p = NULL; /* Store the sentinal value. */ #ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO - while ((c = read(STDIN_FILENO, buf, BUFSIZ)) != 0) { + while ((c = safe_read(STDIN_FILENO, buf, BUFSIZ)) > 0) { for (p=files ; *p ; p++) { fwrite(buf, 1, c, *p); } } + if (c < 0) { /* Make sure read errors are signaled. */ + retval = EXIT_FAILURE; + } + #ifdef CONFIG_FEATURE_CLEAN_UP RELEASE_CONFIG_BUFFER(buf); #endif |