From ba847c6e7fc1da1e6921dcfef164a7efe2ee3b48 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 5 May 2018 20:02:58 +0200 Subject: [PATCH] af_alg: Fix bug on empty files. * lib/af_alg.c (afalg_stream): Ignore the kernel's result if the input stream is empty. --- ChangeLog | 6 ++++++ lib/af_alg.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0f65014692..6704802f95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-05-05 Bruno Haible + + 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 sys-limits.h: new file for crypto and safe I/O diff --git a/lib/af_alg.c b/lib/af_alg.c index 1f4a6aab51..06344b1d60 100644 --- a/lib/af_alg.c +++ b/lib/af_alg.c @@ -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) -- 2.39.5