commit 7033c7ab53f3151a01ead269b25a5ad37aa1aa05
parent 63e954437fe11575d32ad0c17cc6c92c6c31ab6b
Author: Michael Savage <mikejsavage@gmail.com>
Date: Wed, 18 Mar 2015 08:22:21 +0000
Check for malloc failure in symmetric.decrypt
Diffstat:
1 file changed, 5 insertions(+), 0 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -91,6 +91,11 @@ static int luasymmetric_decrypt( lua_State * const L ) {
const size_t message_len = ciphertext_len - crypto_secretbox_NONCEBYTES - crypto_secretbox_MACBYTES;
char * const message = malloc( message_len );
+ if( message == NULL ) {
+ lua_pushliteral( L, "out of memory" );
+ return lua_error( L );
+ }
+
const int ok = crypto_secretbox_open_easy( message,
ciphertext + crypto_secretbox_NONCEBYTES, ciphertext_len - crypto_secretbox_NONCEBYTES,
ciphertext, key );