1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-17 15:32:10 +08:00

librhash: Avoid signed left-shift overflow

Fix `rhash_md5_final` to use unsigned integers for left shifting to
avoid the possibility of undefined overflow behavior.
This commit is contained in:
Brad King
2016-11-09 11:43:34 -05:00
parent fc2cb74fee
commit 465a85fb46

View File

@@ -213,8 +213,8 @@ void rhash_md5_final(md5_ctx *ctx, unsigned char* result)
/* pad message and run for last block */
/* append the byte 0x80 to the message */
ctx->message[index] &= ~(0xFFFFFFFF << shift);
ctx->message[index++] ^= 0x80 << shift;
ctx->message[index] &= ~(0xFFFFFFFFu << shift);
ctx->message[index++] ^= 0x80u << shift;
/* if no room left in the message to store 64-bit message length */
if (index > 14) {