summaryrefslogtreecommitdiff
path: root/lib/sha256.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sha256.c')
-rw-r--r--lib/sha256.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/sha256.c b/lib/sha256.c
index a036befcafd..c518517077c 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -36,11 +36,11 @@
# include "unlocked-io.h"
#endif
+#include <byteswap.h>
#ifdef WORDS_BIGENDIAN
# define SWAP(n) (n)
#else
-# define SWAP(n) \
- (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+# define SWAP(n) bswap_32 (n)
#endif
#define BLOCKSIZE 32768
@@ -208,6 +208,14 @@ 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() as EOF may
+ not be sticky. For details of such systems, see:
+ https://sourceware.org/bugzilla/show_bug.cgi?id=1190 */
+ if (feof (stream))
+ goto process_partial_block;
+
n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
sum += n;
@@ -227,12 +235,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