summaryrefslogtreecommitdiff
path: root/random
diff options
context:
space:
mode:
authorJoe Orton <jorton@apache.org>2012-12-11 11:56:10 +0000
committerJoe Orton <jorton@apache.org>2012-12-11 11:56:10 +0000
commit0a1f996444dff81fdd422bd358310c0a15919fc8 (patch)
tree910fd06bc7db1ddfe0ab3fbf46ef6998f7a0a14c /random
parent79f53b283ad359e3c10da41a6e4072ab65ab95a3 (diff)
downloadapr-0a1f996444dff81fdd422bd358310c0a15919fc8.tar.gz
* random/unix/sha2.c (apr__SHA256_Final): Avoid C pointer aliasing
violation. Submitted by: Jan Kaluza <jkaluza redhat.com> git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1420109 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'random')
-rw-r--r--random/unix/sha2.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/random/unix/sha2.c b/random/unix/sha2.c
index 1f5c1b2e8..12c257d1f 100644
--- a/random/unix/sha2.c
+++ b/random/unix/sha2.c
@@ -465,7 +465,14 @@ void apr__SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
*context->buffer = 0x80;
}
/* Set the bit count: */
- *(sha2_word64*)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount;
+ {
+ union dummy {
+ apr_uint64_t bitcount;
+ apr_byte_t bytes[8];
+ } bitcount;
+ bitcount.bitcount = context->bitcount;
+ MEMCPY_BCOPY(&context->buffer[SHA256_SHORT_BLOCK_LENGTH], bitcount.bytes, 8);
+ }
/* Final transform: */
apr__SHA256_Transform(context, (sha2_word32*)context->buffer);