If I run

cksum -a sha256x -ph /dev/fd/3 < /home/_sysupgrade/base68.tgz 3>&1 >/mnt/falcon

and the filesystem mounted on /mnt is too small to hold base68.tgz,
cksum(1) should return an error.  Instead, the error is silently
ignored, resulting in /mnt/falcon being truncated

The following diff fixes the bug:

Index: bin/md5/md5.c
===================================================================
RCS file: /cvs/src/bin/md5/md5.c,v
retrieving revision 1.95
diff -u -p -r1.95 md5.c
--- bin/md5/md5.c       18 May 2019 16:53:39 -0000      1.95
+++ bin/md5/md5.c       30 Sep 2020 19:18:35 -0000
@@ -504,8 +504,8 @@ digest_file(const char *file, struct has
        }
        while ((nread = fread(data, 1UL, sizeof(data), fp)) != 0) {
                if (echo) {
-                       (void)fwrite(data, nread, 1UL, stdout);
-                       if (fflush(stdout) != 0)
+                       if (fwrite(data, 1UL, nread, stdout) != nread ||
+                           fflush(stdout) != 0 || ferror(stdout) != 0)
                                err(1, "stdout: write error");
                }
                TAILQ_FOREACH(hf, hl, tailq)

Reply via email to