On Wed, 30 Sep 2020 15:25:36 -0400, "Demi M. Obenour" wrote:

> If I run
>
> cksum -a sha256x -ph /dev/fd/3 < /home/_sysupgrade/base68.tgz 3>&1 >/mnt/falc
> on
>
> 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

Just checking the error flag with ferror() is sufficient.

 - todd

Index: bin/md5/md5.c
===================================================================
RCS file: /cvs/src/bin/md5/md5.c,v
retrieving revision 1.95
diff -u -p -u -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:29:09 -0000
@@ -505,7 +505,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)
+                       (void)fflush(stdout);
+                       if (ferror(stdout))
                                err(1, "stdout: write error");
                }
                TAILQ_FOREACH(hf, hl, tailq)

Reply via email to