[PATCH] md5: fix strict aliasing warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is the same fix as was merged in gcc/binutils where this code
appears to originate from.

Signed-off-by: Mike Frysinger <vapier@xxxxxxxxxx>
---
 lib/md5.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/md5.c b/lib/md5.c
index 26ec4bb..488d16e 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -138,9 +138,12 @@ void MD5Final(unsigned char digest[MD5LENGTH], struct MD5Context *ctx)
     }
     byteReverse(ctx->in, 14);
 
-    /* Append length in bits and transform */
-    ((uint32_t *) ctx->in)[14] = ctx->bits[0];
-    ((uint32_t *) ctx->in)[15] = ctx->bits[1];
+    /* Append length in bits and transform.
+     * Use memcpy to avoid aliasing problems.  On most systems,
+     * this will be optimized away to the same code.
+     */
+    memcpy(&ctx->in[14 * sizeof(uint32_t)], &ctx->bits[0], 4);
+    memcpy(&ctx->in[15 * sizeof(uint32_t)], &ctx->bits[1], 4);
 
     MD5Transform(ctx->buf, (uint32_t *) ctx->in);
     byteReverse((unsigned char *) ctx->buf, 4);
-- 
1.7.12

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux