summaryrefslogtreecommitdiff
path: root/lib/sha512.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2018-06-24 01:46:10 -0700
committerPádraig Brady <P@draigBrady.com>2018-06-24 13:53:45 -0700
commit20c918561e6af48b03f3dbaa7553dfd688fd9732 (patch)
treeedf1b79a60ea7e3fd7c41843728fc1ec45c9f683 /lib/sha512.c
parent4208523235711502ad50692ff8cc2014f3b568e5 (diff)
downloadgnulib-20c918561e6af48b03f3dbaa7553dfd688fd9732.tar.gz
af_alg: avoid hangs when reading from streams
* lib/af_alg.c (afalg_stream): Don't assume EOF is sticky, and thus avoid doing a fread() when feof() is set. * lib/md5.c: Ensure feof() is called before fread(). * lib/sha1.c: Likewise. * lib/sha256.c: Likewise. * lib/sha512.c: Likewise.
Diffstat (limited to 'lib/sha512.c')
-rw-r--r--lib/sha512.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/sha512.c b/lib/sha512.c
index 503a54fe8a..863d6ba7ac 100644
--- a/lib/sha512.c
+++ b/lib/sha512.c
@@ -209,6 +209,12 @@ shaxxx_stream (FILE *stream, char const *alg, void *resblock,
/* Read block. Take care for partial reads. */
while (1)
{
+ /* Either process a partial fread() from this loop,
+ or the fread() in afalg_stream may have gotten EOF.
+ We need to avoid a subsequent fread() due to glibc BZ 1190. */
+ if (feof (stream))
+ goto process_partial_block;
+
n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
sum += n;
@@ -228,12 +234,6 @@ shaxxx_stream (FILE *stream, char const *alg, void *resblock,
}
goto process_partial_block;
}
-
- /* We've read at least one byte, so ignore errors. But always
- check for EOF, since feof may be true even though N > 0.
- Otherwise, we could end up calling fread after EOF. */
- if (feof (stream))
- goto process_partial_block;
}
/* Process buffer with BLOCKSIZE bytes. Note that