Subject: bug#17149: shred - tape data

From: Pádraig Brady <[email-masked]>
Date: Thu, 03 Apr 2014 14:39:08 +0100

On 04/03/2014 07:29 AM, Paul Eggert wrote:
> Pádraig Brady wrote:
>> The code looks good.
> 
> Thanks for the review.  I installed the patch and am marking this bug as done.

A test needs an adjustment also due to assuming that
writing to an empty file was a valid thing for shred to be doing.

The attached should fix it up.

thanks,
Pádraig.
>From 8de0db32e546d5a661d6ecde27aef4e5aa6e624f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Thu, 3 Apr 2014 13:47:48 +0100
Subject: [PATCH] tests: fix false failure from previous shred change

* src/shred.c (do_wipefd): Increase the size to OFF_T_MAX,
in the edge case where we do overflow.
* NEWS: Mention the shred improvement from the previous fix.
* tests/misc/shred-passes.sh: Adjust as we no longer
write a BLKSIZE of data for empty files.
Prompted by the continuous integration build failure at:
http://hydra.nixos.org/build/9974238
---
 NEWS                       |    3 +++
 src/shred.c                |    2 ++
 tests/misc/shred-passes.sh |   10 +++++-----
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index d6aa885..c6451b2 100644
--- a/NEWS
+++ b/NEWS
@@ -57,6 +57,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   causing name look-up errors.  Also look-ups are first done outside the chroot,
   in case the look-up within the chroot fails due to library conflicts etc.
 
+  shred now supports multiple passes on GNU/Linux tape devices by rewinding
+  the tape before each pass.  Also redundant writes to empty files are avoided.
+
   split avoids unnecessary input buffering, immediately writing input to output
   which is significant with --filter or when writing to fifos or stdout etc.
 
diff --git a/src/shred.c b/src/shred.c
index 0a53a16..8cd1517 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -893,6 +893,8 @@ do_wipefd (int fd, char const *qname, struct randint_source *s,
                   off_t size_incr = ST_BLKSIZE (st) - remainder;
                   if (! INT_ADD_OVERFLOW (size, size_incr))
                     size += size_incr;
+                  else
+                    size = OFF_T_MAX;
                 }
             }
         }
diff --git a/tests/misc/shred-passes.sh b/tests/misc/shred-passes.sh
index bbd1288..268af95 100755
--- a/tests/misc/shred-passes.sh
+++ b/tests/misc/shred-passes.sh
@@ -20,9 +20,9 @@
 print_ver_ shred

-# shred a single letter, zero length file which should result in
+# shred a single letter, which should result in
 # 3 random passes and a single rename.
-touch f || framework_failure_
+printf 1 > f || framework_failure_
 echo "\
 shred: f: pass 1/3 (random)...
 shred: f: pass 2/3 (random)...
@@ -35,15 +35,15 @@ shred -v -u f 2>out || fail=1
 
 compare exp out || fail=1
 
-# Likewise but with --exact to bypass the
-# data passes for the zero length file
+# Likewise but for a zero length file
+# to bypass the data passes
 touch f || framework_failure_
 echo "\
 shred: f: removing
 shred: f: renamed to 0
 shred: f: removed" > exp || framework_failure_
 
-shred -x -v -u f 2>out || fail=1
+shred -v -u f 2>out || fail=1
 
 compare exp out || fail=1
 
-- 
1.7.7.6