diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-22 09:23:54 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-22 09:29:22 +0200 |
commit | 836580a7d690dcdade82ce6bdd1f172af1417d0e (patch) | |
tree | ff6a39fc686fea75a11367520db144bbaedaed14 /coreutils | |
parent | ea9b96e5aab5a42518041e04b5d2780f6af80c7a (diff) | |
download | busybox-w32-836580a7d690dcdade82ce6bdd1f172af1417d0e.tar.gz busybox-w32-836580a7d690dcdade82ce6bdd1f172af1417d0e.tar.bz2 busybox-w32-836580a7d690dcdade82ce6bdd1f172af1417d0e.zip |
cksum: fix handling of read errors
function old new delta
cksum_main 377 399 +22
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/cksum.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/coreutils/cksum.c b/coreutils/cksum.c index ecc43857d..6b601b752 100644 --- a/coreutils/cksum.c +++ b/coreutils/cksum.c | |||
@@ -14,8 +14,9 @@ | |||
14 | //config: bool "crc32 (4.1 kb)" | 14 | //config: bool "crc32 (4.1 kb)" |
15 | //config: default y | 15 | //config: default y |
16 | 16 | ||
17 | // APPLET_NOEXEC:name main location suid_type help | ||
17 | //applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) | 18 | //applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) |
18 | //applet:IF_CKSUM(APPLET_NOEXEC(crc32, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) | 19 | //applet:IF_CRC32(APPLET_NOEXEC(crc32, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum)) |
19 | /* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ | 20 | /* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */ |
20 | 21 | ||
21 | //kbuild:lib-$(CONFIG_CKSUM) += cksum.o | 22 | //kbuild:lib-$(CONFIG_CKSUM) += cksum.o |
@@ -31,8 +32,8 @@ | |||
31 | 32 | ||
32 | /* This is a NOEXEC applet. Be very careful! */ | 33 | /* This is a NOEXEC applet. Be very careful! */ |
33 | 34 | ||
34 | #define IS_CRC32 (ENABLE_CRC32 && (!ENABLE_CKSUM || applet_name[1] == 'r')) | ||
35 | #define IS_CKSUM (ENABLE_CKSUM && (!ENABLE_CRC32 || applet_name[1] == 'k')) | 35 | #define IS_CKSUM (ENABLE_CKSUM && (!ENABLE_CRC32 || applet_name[1] == 'k')) |
36 | #define IS_CRC32 (ENABLE_CRC32 && (!ENABLE_CKSUM || applet_name[1] == 'r')) | ||
36 | 37 | ||
37 | int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 38 | int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
38 | int cksum_main(int argc UNUSED_PARAM, char **argv) | 39 | int cksum_main(int argc UNUSED_PARAM, char **argv) |
@@ -51,7 +52,8 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) | |||
51 | do { | 52 | do { |
52 | uint32_t crc; | 53 | uint32_t crc; |
53 | off_t filesize; | 54 | off_t filesize; |
54 | int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input); | 55 | const char *fname = *argv ? *argv : bb_msg_standard_input; |
56 | int fd = open_or_warn_stdin(fname); | ||
55 | 57 | ||
56 | if (fd < 0) { | 58 | if (fd < 0) { |
57 | exit_code = EXIT_FAILURE; | 59 | exit_code = EXIT_FAILURE; |
@@ -63,6 +65,8 @@ int cksum_main(int argc UNUSED_PARAM, char **argv) | |||
63 | #define read_buf bb_common_bufsiz1 | 65 | #define read_buf bb_common_bufsiz1 |
64 | for (;;) { | 66 | for (;;) { |
65 | int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE); | 67 | int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE); |
68 | if (bytes_read < 0) | ||
69 | bb_simple_perror_msg_and_die(fname); | ||
66 | if (bytes_read > 0) { | 70 | if (bytes_read > 0) { |
67 | filesize += bytes_read; | 71 | filesize += bytes_read; |
68 | } else { | 72 | } else { |