]> wimlib.net Git - wimlib/commitdiff
sha1.c: Annotate potential unaligned memory accesses in sha1_final()
authorEric Biggers <ebiggers3@gmail.com>
Thu, 20 Nov 2014 03:43:21 +0000 (21:43 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 20 Nov 2014 03:46:00 +0000 (21:46 -0600)
include/wimlib/unaligned.h
src/sha1.c

index 9d70806529c0786e0ab7502e4654b6175c709213..7c2ade22031894debbf1f449295c5499d32faf96 100644 (file)
@@ -34,6 +34,7 @@ store_##type##_unaligned(type val, void *p)                   \
 DEFINE_UNALIGNED_TYPE(le16);
 DEFINE_UNALIGNED_TYPE(le32);
 DEFINE_UNALIGNED_TYPE(le64);
 DEFINE_UNALIGNED_TYPE(le16);
 DEFINE_UNALIGNED_TYPE(le32);
 DEFINE_UNALIGNED_TYPE(le64);
+DEFINE_UNALIGNED_TYPE(be32);
 DEFINE_UNALIGNED_TYPE(size_t);
 
 #endif /* _WIMLIB_UNALIGNED_H */
 DEFINE_UNALIGNED_TYPE(size_t);
 
 #endif /* _WIMLIB_UNALIGNED_H */
index 9ed26fd1ebe418d36eb3f9373d4baaf255cc0139..1b2abb2f226a3b293a55347c5ec541b2cbc26f9e 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "wimlib/endianness.h"
 #include "wimlib/sha1.h"
 
 #include "wimlib/endianness.h"
 #include "wimlib/sha1.h"
+#include "wimlib/unaligned.h"
 
 /* Dummy SHA-1 message digest of all 0's.  This is used in the WIM format to
  * mean "SHA-1 not specified".  */
 
 /* Dummy SHA-1 message digest of all 0's.  This is used in the WIM format to
  * mean "SHA-1 not specified".  */
@@ -203,13 +204,12 @@ sha1_final(u8 md[20], SHA_CTX *ctx)
         * final length is a multiple of the block size.  */
        static const u8 padding[64] = {0x80, };
        be64 finalcount = cpu_to_be64(ctx->bytecount << 3);
         * final length is a multiple of the block size.  */
        static const u8 padding[64] = {0x80, };
        be64 finalcount = cpu_to_be64(ctx->bytecount << 3);
-       be32 *out = (be32 *)md;
 
        sha1_update(ctx, padding, 64 - ((ctx->bytecount + 8) & 63));
        sha1_update(ctx, &finalcount, 8);
 
        for (int i = 0; i < 5; i++)
 
        sha1_update(ctx, padding, 64 - ((ctx->bytecount + 8) & 63));
        sha1_update(ctx, &finalcount, 8);
 
        for (int i = 0; i < 5; i++)
-               out[i] = cpu_to_be32(ctx->state[i]);
+               store_be32_unaligned(cpu_to_be32(ctx->state[i]), &md[i * 4]);
 }
 
 /* Calculate the SHA-1 message digest of the specified buffer.
 }
 
 /* Calculate the SHA-1 message digest of the specified buffer.