fix-aliasing.patch 1.1 KB

123456789101112131415161718192021222324
  1. --- a/src/auth_sha2.c
  2. +++ b/src/auth_sha2.c
  3. @@ -511,7 +517,8 @@
  4. *context->buffer = 0x80;
  5. }
  6. /* Set the bit count: */
  7. - *(u_int64_t *)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
  8. + /* Use memcpy so we're not casting or aliasing */
  9. + memcpy(&context->buffer[SHA256_SHORT_BLOCK_LENGTH], &context->bitcount, sizeof (context->bitcount));
  10. /* Final transform: */
  11. sha256_transform(context, context->buffer);
  12. @@ -789,8 +796,8 @@
  13. *context->buffer = 0x80;
  14. }
  15. /* Store the length of input data (in bits): */
  16. - *(u_int64_t *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH] = context->bitcount[1];
  17. - *(u_int64_t *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0];
  18. + memcpy(&context->buffer+SHA512_SHORT_BLOCK_LENGTH, &context->bitcount+1, sizeof (context->bitcount+1));
  19. + memcpy(&context->buffer+SHA512_SHORT_BLOCK_LENGTH+8, &context->bitcount, sizeof (context->bitcount));
  20. /* Final transform: */
  21. sha512_transform(context, context->buffer);