]> Savannah Git Hosting - gnulib.git/commitdiff
af_alg: Fix bug on empty files.
authorBruno Haible <bruno@clisp.org>
Sat, 5 May 2018 18:02:58 +0000 (20:02 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 5 May 2018 18:02:58 +0000 (20:02 +0200)
* lib/af_alg.c (afalg_stream): Ignore the kernel's result if the input
stream is empty.

ChangeLog
lib/af_alg.c

index 0f6501469291115ce8c2614381b29735e9382ca6..6704802f95d558ebc540432687e57db7be543096 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-05-05  Bruno Haible  <bruno@clisp.org>
+
+       af_alg: Fix bug on empty files.
+       * lib/af_alg.c (afalg_stream): Ignore the kernel's result if the input
+       stream is empty.
+
 2018-05-05  Paul Eggert  <eggert@cs.ucla.edu>
 
        sys-limits.h: new file for crypto and safe I/O
index 1f4a6aab515207e9b878160d1d95392e216c5033..06344b1d602e8fb2d1d29870c70956d42f959af9 100644 (file)
@@ -83,10 +83,12 @@ afalg_stream (FILE * stream, const char *alg, void *resblock, ssize_t hashlen)
   else
     {
       /* sendfile not possible, do a classic read-write loop.  */
+      int non_empty = 0;
       ssize_t size;
       char buf[BLOCKSIZE];
       while ((size = fread (buf, 1, sizeof buf, stream)))
         {
+          non_empty = 1;
           if (send (ofd, buf, size, MSG_MORE) != size)
             {
               ret = -EIO;
@@ -98,6 +100,13 @@ afalg_stream (FILE * stream, const char *alg, void *resblock, ssize_t hashlen)
           ret = -EIO;
           goto out_ofd;
         }
+      /* On Linux 4.4.0 at least, the value for an empty stream is wrong
+         (all zeroes).  */
+      if (!non_empty)
+        {
+          ret = -EAFNOSUPPORT;
+          goto out_ofd;
+        }
     }
 
   if (read (ofd, resblock, hashlen) != hashlen)