diff options
author | sje <sje@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-08-12 16:06:57 +0000 |
---|---|---|
committer | sje <sje@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-08-12 16:06:57 +0000 |
commit | a6f88a9ab42b3225611705f8cdf28800f75799f7 (patch) | |
tree | 8fa236a1f2f2f08b6de61f3772bd68a38b31f57f /libiberty | |
parent | d366ae5ae3cec0c636d9238a611b6cedc7419dd1 (diff) | |
download | gcc-a6f88a9ab42b3225611705f8cdf28800f75799f7.tar.gz |
2011-08-12 Steve Ellcey <sje@cup.hp.com>
* md5.c (md5_read_ctx): Handle mis-aligned resbuf pointer.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177700 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty')
-rw-r--r-- | libiberty/ChangeLog | 4 | ||||
-rw-r--r-- | libiberty/md5.c | 16 |
2 files changed, 14 insertions, 6 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index fe9da85587f..eabc69dc7ff 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,7 @@ +2011-08-12 Steve Ellcey <sje@cup.hp.com> + + * md5.c (md5_read_ctx): Handle mis-aligned resbuf pointer. + 2011-08-06 Uros Bizjak <ubizjak@gmail.com> * testsuite/test-expandargv.c (writeout_test): Check result of fwrite. diff --git a/libiberty/md5.c b/libiberty/md5.c index 9de9d88c22a..11920e1b555 100644 --- a/libiberty/md5.c +++ b/libiberty/md5.c @@ -76,15 +76,19 @@ md5_init_ctx (struct md5_ctx *ctx) /* Put result from CTX in first 16 bytes following RESBUF. The result must be in little endian byte order. - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32 bits value. */ + IMPORTANT: RESBUF may not be aligned as strongly as MD5_UNIT32 so we + put things in a local (aligned) buffer first, then memcpy into RESBUF. */ void * md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) { - ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A); - ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B); - ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C); - ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D); + md5_uint32 buffer[4]; + + buffer[0] = SWAP (ctx->A); + buffer[1] = SWAP (ctx->B); + buffer[2] = SWAP (ctx->C); + buffer[3] = SWAP (ctx->D); + + memcpy (resbuf, buffer, 16); return resbuf; } |