]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
shred: fix operation on Solaris with 64 bit builds
authorPádraig Brady <P@draigBrady.com>
Wed, 23 Aug 2023 14:21:01 +0000 (15:21 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 23 Aug 2023 14:23:42 +0000 (15:23 +0100)
* NEWS: Mention the bug fix.
* gl/lib/randread.c (get_nonce): Limit getrandom() <= 1024 bytes.

NEWS
gl/lib/randread.c

diff --git a/NEWS b/NEWS
index a104c97a264583befb44306cf555105f37e0aa13..153bd5d59d7aa7f89e2b96b2fe3393c3bbacc0e0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   'pr --length=1 --double-space' no longer enters an infinite loop.
   [This bug was present in "the beginning".]
 
+  shred again operates on Solaris when built for 64 bits.
+  Previously it would have exited with a "getrandom: Invalid argument" error.
+  [bug introduced in coreutils-9.0]
+
   tac now handles short reads on its input.  Previously it may have exited
   erroneously, especially with large input files with no separators.
   [This bug was present in "the beginning".]
index 9c572951d2532dc478f7e7c66007db4f8ea07f81..b729fedbc3ba41a094b5eea15eec825c9b056c05 100644 (file)
@@ -132,7 +132,13 @@ get_nonce (void *buffer, size_t bufsize)
   char *buf = buffer, *buflim = buf + bufsize;
   while (buf < buflim)
     {
-      ssize_t nbytes = getrandom (buf, buflim - buf, 0);
+#if defined __sun
+# define MAX_GETRANDOM 1024
+#else
+# define MAX_GETRANDOM SIZE_MAX
+#endif
+      size_t max_bytes = MIN (buflim - buf, MAX_GETRANDOM);
+      ssize_t nbytes = getrandom (buf, max_bytes, 0);
       if (0 <= nbytes)
         buf += nbytes;
       else if (errno != EINTR)