summaryrefslogtreecommitdiff
path: root/security/pgp5
diff options
context:
space:
mode:
authorfrueauf <frueauf>1999-01-05 14:31:01 +0000
committerfrueauf <frueauf>1999-01-05 14:31:01 +0000
commit1e144551bf7cd79d13ee8de034997d1f335b5db4 (patch)
tree9c593f7f36c626438041ccf99bd8f70a4a1bc5fc /security/pgp5
parent298b91c96bd20599555a51ae1f821c79b97dda5f (diff)
downloadpkgsrc-1e144551bf7cd79d13ee8de034997d1f335b5db4.tar.gz
Add patch that fixes bus error caused by alignment failures on NetBSD/Sparc.
Provided by Julian Coleman <J.D.Coleman@newcastle.ac.uk>.
Diffstat (limited to 'security/pgp5')
-rw-r--r--security/pgp5/patches/patch-ag91
1 files changed, 91 insertions, 0 deletions
diff --git a/security/pgp5/patches/patch-ag b/security/pgp5/patches/patch-ag
new file mode 100644
index 00000000000..2ed6652374f
--- /dev/null
+++ b/security/pgp5/patches/patch-ag
@@ -0,0 +1,91 @@
+$NetBSD: patch-ag,v 1.1 1999/01/05 14:31:01 frueauf Exp $
+
+From Julian Coleman <J.D.Coleman@newcastle.ac.uk> posted to
+netbsd-bugs@netbsd.org:
+
+The memory alignment strategy for PGP 5.0i causes bus errors on NetBSD/Sparc
+because 8 byte variables are not aligned on an 8 byte boundary.
+
+In src/lib/pgp/helper/pgpMem.c:PGP_INTERNAL_ALLOC(), a header is added to
+all malloc()'ed memory and the pointer returned is incremented by the size
+of the header. However, there are no constraints to see if this increment
+is correctly aligned.
+
+The problem might also occur on other OS's running on the Sparc. A patch
+is appended (based on one used for the Chimera web browser).
+
+J
+
+PS. The exact problem is that 'off_t' is an 8 byte value, but the header
+length is only a mulitple of 4. Pgpe crashes at pgpFileMod.c:333, when it
+tries to modify 'context->filesize'.
+
+PPS. Maybe 'long long' should also be in the union (e.g. for Solaris 2).
+
+--- lib/pgp/helper/pgpMem.c.orig Mon Aug 11 02:05:32 1997
++++ lib/pgp/helper/pgpMem.c Tue Jan 5 15:03:27 1999
+@@ -19,6 +19,20 @@
+ #include "pgpDebug.h"
+ #include "pgpLeaks.h"
+
++/*
++ * Make sure any memory chunks are correctly aligned.
++ * This can be forced by defining ALIGNSIZE (in bytes).
++ */
++#ifndef ALIGNSIZE
++typedef struct Alignment
++{
++ union { int a; char *b; size_t c; off_t d; long e; } Align;
++} Alignment;
++#define MEMALIGN(x) ((x / sizeof(Alignment) + 1) * sizeof(Alignment))
++#else
++#define MEMALIGN(x) ((x / ALIGNSIZE + 1) * ALIGNSIZE)
++#endif
++
+ /* Fills allocated/deallocated memory with 0xDD's */
+ #ifndef DEBUG_FILL_MEM
+ #define DEBUG_FILL_MEM DEBUG
+@@ -69,11 +83,11 @@
+ };
+
+ #define UserPtrToMemHeader(userPtr) \
+- ((MemHeader *)((char *)(userPtr) - sizeof(MemHeader)))
++ ((MemHeader *)((char *)(userPtr) - MEMALIGN(sizeof(MemHeader))))
+ #define MemHeaderToUserPtr(hdrPtr) \
+- ((void *)((char *)(hdrPtr) + sizeof(MemHeader)))
++ ((void *)((char *)(hdrPtr) + MEMALIGN(sizeof(MemHeader))))
+ #define FullBlockSize(userSize) \
+- (sizeof(MemHeader) + (userSize) + DEBUG_MEM_TAIL_MAGIC)
++ (MEMALIGN(sizeof(MemHeader)) + (userSize) + DEBUG_MEM_TAIL_MAGIC)
+
+ /*
+ * Defines the sequence of tail magic bytes. We want every byte to be
+@@ -269,7 +283,7 @@
+ MemHeader * header)
+ {
+ #if DEBUG_MEM_TAIL_MAGIC
+- char * tailMagic = (char *)header + sizeof(MemHeader) + header->size;
++ char * tailMagic = (char *)header + MEMALIGN(sizeof(MemHeader)) + header->size;
+ int i;
+
+ for (i = 0; i < DEBUG_MEM_TAIL_MAGIC; i++)
+@@ -287,8 +301,9 @@
+ MemHeader * header;
+ void * userPtr;
+
++ size += (MEMALIGN(sizeof(MemHeader)) - (sizeof(MemHeader)));
+ header = (MemHeader *)pgpPlatformAlloc(FullBlockSize(size));
+-if (header == NULL)
++ if (header == NULL)
+ return NULL;
+
+ MaybeFillMem(header, FullBlockSize(size));
+@@ -352,7 +367,7 @@
+ if (newHeader == NULL)
+ return PGPERR_NOMEM;
+ pgpCopyMemory((void *)oldHeader, (void *)newHeader,
+- sizeof(MemHeader) + oldSize);
++ MEMALIGN(sizeof(MemHeader)) + oldSize);
+ MaybeFillMem(oldHeader, FullBlockSize(oldSize));
+ pgpPlatformFree(oldHeader);
+ }