Package: paperkey
Version: 0.7-1
Severity: serious

Hi David,

As can be seen at [0] paperkey fails to build from source on sparc[1].
The testsuite fails due to unaligned memory access in sha1_read_ctx.

make[3]: Entering directory `/home/weasel/paperkey/paperkey-0.7/checks'
./roundtrip.sh: line 5: 11357 Bus error               ../paperkey --secret-key 
${srcdir}/papertest.sec --output papertest.txt
FAIL: roundtrip.sh
./roundtrip-raw.sh: line 5: 11363 Bus error               ../paperkey 
--secret-key ${srcdir}/papertest.sec --output-type raw --output papertest.bin
FAIL: roundtrip-raw.sh
PASS: bad-crc-base16.sh
PASS: bad-crc-raw.sh
======================================
2 of 4 tests failed


Program terminated with signal 10, Bus error.
#0  0x000125a0 in sha1_read_ctx (ctx=0xffa8368c, resbuf=0xffa837a3) at sha1.c:78
78        ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
(gdb) bt
#0  0x000125a0 in sha1_read_ctx (ctx=0xffa8368c, resbuf=0xffa837a3) at sha1.c:78
#1  0x00011730 in calculate_fingerprint (packet=0x26178, public_len=418, 
fingerprint=0xffa837a3 "Žÿš8Ì÷ü\200") at parse.c:219
#2  0x00011a84 in extract (input=0x26008, outname=0xffa83a13 "papertest.txt", 
output_type=BASE16) at extract.c:51
#3  0xf7e67a3c in __libc_start_main () from /lib/libc.so.6
#4  0x00010a98 in _start ()



This seems to fix the issue:

--- paperkey-0.7.orig/gl/sha1.c
+++ paperkey-0.7/gl/sha1.c
@@ -67,19 +67,28 @@
   ctx->buflen = 0;
 }
 
+/* Copy the 4 byte value in v into the memory location pointed to by *cp,
+   If your architecture allows unaligend access this should be equivalent
+   to *cp = v */
+void
+set_uint32(char *cp, uint32_t v)
+{
+  memcpy(cp,&v,4);
+}
+
 /* Put result from CTX in first 20 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-bit value.  */
 void *
-sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
+sha1_read_ctx (const struct sha1_ctx *ctx, char *resbuf)
 {
-  ((uint32_t *) resbuf)[0] = SWAP (ctx->A);
-  ((uint32_t *) resbuf)[1] = SWAP (ctx->B);
-  ((uint32_t *) resbuf)[2] = SWAP (ctx->C);
-  ((uint32_t *) resbuf)[3] = SWAP (ctx->D);
-  ((uint32_t *) resbuf)[4] = SWAP (ctx->E);
+  set_uint32(&resbuf[0*4], SWAP (ctx->A));
+  set_uint32(&resbuf[1*4], SWAP (ctx->B));
+  set_uint32(&resbuf[2*4], SWAP (ctx->C));
+  set_uint32(&resbuf[3*4], SWAP (ctx->D));
+  set_uint32(&resbuf[4*4], SWAP (ctx->E));
 
   return resbuf;
 }


Cheers,
Peter

0. http://buildd.debian.org/paperkey 
1. 
http://buildd.debian.org/fetch.cgi?pkg=paperkey;ver=0.7-1;arch=sparc;stamp=1191826910
-- 
                           |  .''`.  ** Debian GNU/Linux **
      Peter Palfrader      | : :' :      The  universal
 http://www.palfrader.org/ | `. `'      Operating System
                           |   `-    http://www.debian.org/


Reply via email to