diff -up coreutils-6.10/lib/sha256.c.sparc coreutils-6.10/lib/sha256.c --- coreutils-6.10/lib/sha256.c.sparc 2007-11-25 08:23:31.000000000 -0500 +++ coreutils-6.10/lib/sha256.c 2008-05-29 15:57:56.000000000 -0400 @@ -85,6 +85,15 @@ sha224_init_ctx (struct sha256_ctx *ctx) ctx->buflen = 0; } +/* Copy the value from v into the memory location pointed to by *cp, + If your architecture allows unaligned access this is equivalent to + * (uint32_t *) cp = v */ +static inline void +set_uint32 (char *cp, uint32_t v) +{ + memcpy (cp, &v, sizeof v); +} + /* Put result from CTX in first 32 bytes following RESBUF. The result must be in little endian byte order. @@ -129,9 +138,13 @@ sha256_conclude_ctx (struct sha256_ctx * if (ctx->total[0] < bytes) ++ctx->total[1]; - /* Put the 64-bit file length in *bits* at the end of the buffer. */ - ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29)); - ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3); + /* Put the 64-bit file length in *bits* at the end of the buffer. + Use set_uint32 rather than a simple assignment, to avoid risk of + unaligned access. */ + set_uint32 ((char *) &ctx->buffer[size - 2], + SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29))); + set_uint32 ((char *) &ctx->buffer[size - 1], + SWAP (ctx->total[0] << 3)); memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes); diff -up coreutils-6.10/lib/sha512.c.sparc coreutils-6.10/lib/sha512.c --- coreutils-6.10/lib/sha512.c.sparc 2007-11-25 08:23:31.000000000 -0500 +++ coreutils-6.10/lib/sha512.c 2008-05-29 15:58:49.000000000 -0400 @@ -92,6 +92,15 @@ sha384_init_ctx (struct sha512_ctx *ctx) ctx->buflen = 0; } +/* Copy the value from V into the memory location pointed to by *CP, + If your architecture allows unaligned access, this is equivalent to + * (__typeof__ (v) *) cp = v */ +static inline void +set_uint64 (char *cp, u64 v) +{ + memcpy (cp, &v, sizeof v); +} + /* Put result from CTX in first 64 bytes following RESBUF. The result must be in little endian byte order. @@ -136,10 +145,14 @@ sha512_conclude_ctx (struct sha512_ctx * if (u64lt (ctx->total[0], u64lo (bytes))) ctx->total[1] = u64plus (ctx->total[1], u64lo (1)); - /* Put the 64-bit file length in *bits* at the end of the buffer. */ - ctx->buffer[size - 2] = SWAP (u64or (u64shl (ctx->total[1], 3), - u64shr (ctx->total[0], 61))); - ctx->buffer[size - 1] = SWAP (u64shl (ctx->total[0], 3)); + /* Put the 128-bit file length in *bits* at the end of the buffer. + Use set_uint64 rather than a simple assignment, to avoid risk of + unaligned access. */ + set_uint64 ((char *) &ctx->buffer[size - 2], + SWAP (u64or (u64shl (ctx->total[1], 3), + u64shr (ctx->total[0], 61)))); + set_uint64 ((char *) &ctx->buffer[size - 1], + SWAP (u64shl (ctx->total[0], 3))); memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 8 - bytes); diff -up coreutils-6.10/src/Makefile.am.BAD coreutils-6.10/src/Makefile.am --- coreutils-6.10/src/Makefile.am.BAD 2008-05-29 16:42:30.000000000 -0400 +++ coreutils-6.10/src/Makefile.am 2008-05-29 16:43:00.000000000 -0400 @@ -99,6 +99,7 @@ shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME) mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME) vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) +tac_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) ## If necessary, add -lm to resolve use of pow in lib/strtod.c. sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME) diff -up coreutils-6.10/src/Makefile.in.BAD coreutils-6.10/src/Makefile.in --- coreutils-6.10/src/Makefile.in.BAD 2008-05-29 16:43:31.000000000 -0400 +++ coreutils-6.10/src/Makefile.in 2008-05-29 16:44:03.000000000 -0400 @@ -1242,6 +1242,7 @@ shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME) mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME) vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_ACL) sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME) +tac_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) # for get_date and gettime date_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)