summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-22 09:23:54 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-22 09:29:22 +0200
commit836580a7d690dcdade82ce6bdd1f172af1417d0e (patch)
treeff6a39fc686fea75a11367520db144bbaedaed14
parentea9b96e5aab5a42518041e04b5d2780f6af80c7a (diff)
cksum: fix handling of read errors
function old new delta cksum_main 377 399 +22 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/cksum.c10
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 @@
//config: bool "crc32 (4.1 kb)"
//config: default y
+// APPLET_NOEXEC:name main location suid_type help
//applet:IF_CKSUM(APPLET_NOEXEC(cksum, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
-//applet:IF_CKSUM(APPLET_NOEXEC(crc32, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
+//applet:IF_CRC32(APPLET_NOEXEC(crc32, cksum, BB_DIR_USR_BIN, BB_SUID_DROP, cksum))
/* bb_common_bufsiz1 usage here is safe wrt NOEXEC: not expecting it to be zeroed. */
//kbuild:lib-$(CONFIG_CKSUM) += cksum.o
@@ -31,8 +32,8 @@
/* This is a NOEXEC applet. Be very careful! */
-#define IS_CRC32 (ENABLE_CRC32 && (!ENABLE_CKSUM || applet_name[1] == 'r'))
#define IS_CKSUM (ENABLE_CKSUM && (!ENABLE_CRC32 || applet_name[1] == 'k'))
+#define IS_CRC32 (ENABLE_CRC32 && (!ENABLE_CKSUM || applet_name[1] == 'r'))
int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cksum_main(int argc UNUSED_PARAM, char **argv)
@@ -51,7 +52,8 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
do {
uint32_t crc;
off_t filesize;
- int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
+ const char *fname = *argv ? *argv : bb_msg_standard_input;
+ int fd = open_or_warn_stdin(fname);
if (fd < 0) {
exit_code = EXIT_FAILURE;
@@ -63,6 +65,8 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
#define read_buf bb_common_bufsiz1
for (;;) {
int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE);
+ if (bytes_read < 0)
+ bb_simple_perror_msg_and_die(fname);
if (bytes_read > 0) {
filesize += bytes_read;
} else {