To reproduce:

$ dd if=/dev/null of=/tmp/dd.test bs=1m seek=$((1 << 24))
0+0 records in
0+0 records out
0 bytes transferred in 0.000 secs (0 bytes/sec)
$

Patch:

diff -rup /usr/src/bin/dd/dd.c dd/dd.c
--- /usr/src/bin/dd/dd.c        Sun Oct 24 23:24:21 2021
+++ dd/dd.c     Thu May 19 20:29:31 2022
@@ -161,7 +161,8 @@ setup(void)
         * kinds of output files, tapes, for example.
         */
        if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK))
-               (void)ftruncate(out.fd, out.offset * out.dbsz);
+               if (ftruncate(out.fd, out.offset * out.dbsz) && (out.flags & 
ISREG))
+                       err(1, "%s", out.name);
 
        /*
         * If converting case at the same time as another conversion, build a
@@ -212,6 +213,8 @@ getfdtype(IO *io)
                io->flags |= ioctl(io->fd, MTIOCGET, &mt) ? ISCHR : ISTAPE;
        if (S_ISFIFO(sb.st_mode) || S_ISSOCK(sb.st_mode))
                io->flags |= ISPIPE;
+       if (S_ISREG(sb.st_mode))
+               io->flags |= ISREG;
 }
 
 static void
diff -rup /usr/src/bin/dd/dd.h dd/dd.h
--- /usr/src/bin/dd/dd.h        Sat Feb 16 11:54:00 2019
+++ dd/dd.h     Sat May  7 02:49:15 2022
@@ -47,7 +47,8 @@ typedef struct {
 #define        ISCHR           0x01            /* character device (warn on 
short) */
 #define        ISPIPE          0x02            /* pipe (not truncatable) */
 #define        ISTAPE          0x04            /* tape (not seekable) */
-#define        NOREAD          0x08            /* not readable */
+#define        ISREG           0x08            /* regular file (warn on 
truncation errors) */
+#define        NOREAD          0x10            /* not readable */
        u_int   flags;
 
        char    *name;                  /* name */

Reply via email to