[1186] in BarnOwl Developers
[D-O-H] r1127 - trunk/owl
daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:13:54 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
X-Original-To: nelhage@nelhage.com
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Mon, 15 Sep 2008 23:43:56 -0400 (EDT)
Author: asedeno
Date: 2008-09-15 23:43:56 -0400 (Mon, 15 Sep 2008)
New Revision: 1127
Modified:
trunk/owl/functions.c
Log:
Fix the zcrypt bug.
This should fix the segfault on short zcrpyt messages.
As added bonuses, it documents the length of the cryptmsg buffer and
plugs a small memory leak.
Modified: trunk/owl/functions.c
===================================================================
--- trunk/owl/functions.c 2008-09-16 01:09:36 UTC (rev 1126)
+++ trunk/owl/functions.c 2008-09-16 03:43:56 UTC (rev 1127)
@@ -421,12 +421,21 @@
mymsg=owl_zwrite_get_message(&z);
#ifdef OWL_ENABLE_ZCRYPT
- cryptmsg=owl_malloc(strlen(mymsg)*4);
+ /* Allocate enough space for the crypted message. For each byte of
+ * the message, the encoded cyphertext will have two bytes. Block
+ * size is 8 bytes of input, or 16 bytes of output, so make sure we
+ * have at least one block worth of space allocated. If the message
+ * is empty, no blocks are sent, but we still allocate one
+ * block. The additional 16 bytes also provide space for the null
+ * terminator, as we will never use all of it for cyphertext.
+ */
+ cryptmsg=owl_malloc((strlen(mymsg)*2)+16);
ret=owl_zcrypt_encrypt(cryptmsg, mymsg, owl_zwrite_get_class(&z), owl_zwrite_get_instance(&z));
if (ret) {
owl_function_error("Error in zcrypt, possibly no key found. Message not sent.");
owl_function_beep();
owl_free(cryptmsg);
+ owl_zwrite_free(&z);
return;
}
#else