$OpenBSD: patch-src_rfc2440_c,v 1.2 2014/11/30 05:41:35 brad Exp $

- Don't use malloc.h header on OpenBSD
- Fix segv : http://sourceforge.net/p/mcrypt/patches/13/

--- src/rfc2440.c.orig	Sun Nov 16 14:50:01 2008
+++ src/rfc2440.c	Thu Nov 20 02:24:36 2014
@@ -23,7 +23,6 @@
 #include <zlib.h>
 #endif
 #include <stdio.h>
-#include <malloc.h>
 
 #include "xmalloc.h"
 #include "keys.h"
@@ -497,7 +496,7 @@ plaintext_encode(const USTRING dat)
     time_t t;
 
     assert(dat->len > 0);
-    result = make_ustring( NULL,  2 * dat->len); /* xxx */
+    result = make_ustring( NULL,  dat->len + 12); /* xxx */
     newdat = (USTRING)dat;
     result->d[pos++] = (0x80 | 0x40 | PKT_PLAINTEXT);
 
@@ -810,7 +809,8 @@ encrypted_encode(const USTRING pt, const DEK *dek)
     _mcrypt_encrypt(dek->hd, rndpref, dek->blocklen + 2, NULL, 0);
     _mcrypt_sync(dek->hd, rndpref, dek->blocklen);
 
-    ct = make_ustring( rndpref,   2 * pt->len); /* xxx */
+    ct = make_ustring( NULL, dek->blocklen + 2 + pt->len + 12); /* xxx */
+    memcpy(ct->d, rndpref, dek->blocklen + 2);
     pos = dek->blocklen + 2;
     
     _mcrypt_encrypt(dek->hd, ct->d + pos, pt->len, pt->d, pt->len);
