summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Ahern <william@25thandClement.com>2015-12-17 17:42:03 +0800
committerWilliam Ahern <william@25thandClement.com>2015-12-17 17:42:03 +0800
commit67187d3b796abef2836e2425c0c28f1bb48e5233 (patch)
tree33239983a907a287cb31ffc1aa07b0881b77a20c
parentcd859abad9318b2ffb29d9a8caf3342ca01081ec (diff)
downloadluaossl-67187d3b796abef2836e2425c0c28f1bb48e5233.tar.gz
luaossl-67187d3b796abef2836e2425c0c28f1bb48e5233.tar.bz2
luaossl-67187d3b796abef2836e2425c0c28f1bb48e5233.zip
set empty key when creating cipher object to prevent SEGV if caller fails to initialize with a key before calling :update or :final.
closes issue #31.
-rw-r--r--src/openssl.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/openssl.c b/src/openssl.c
index e91e270..01bf2c8 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -6450,13 +6450,19 @@ static const EVP_CIPHER *cipher_checktype(lua_State *L, int index) {
6450static int cipher_new(lua_State *L) { 6450static int cipher_new(lua_State *L) {
6451 const EVP_CIPHER *type; 6451 const EVP_CIPHER *type;
6452 EVP_CIPHER_CTX *ctx; 6452 EVP_CIPHER_CTX *ctx;
6453 unsigned char key[EVP_MAX_KEY_LENGTH] = { 0 };
6453 6454
6454 type = cipher_checktype(L, 1); 6455 type = cipher_checktype(L, 1);
6455 6456
6456 ctx = prepudata(L, sizeof *ctx, CIPHER_CLASS, NULL); 6457 ctx = prepudata(L, sizeof *ctx, CIPHER_CLASS, NULL);
6457 EVP_CIPHER_CTX_init(ctx); 6458 EVP_CIPHER_CTX_init(ctx);
6458 6459
6459 if (!EVP_CipherInit_ex(ctx, type, NULL, NULL, NULL, -1)) 6460 /*
6461 * NOTE: For some ciphers like AES calling :update or :final without
6462 * setting a key causes a SEGV. Set a dummy key here. Same solution
6463 * as used by Ruby OSSL.
6464 */
6465 if (!EVP_CipherInit_ex(ctx, type, NULL, key, NULL, -1))
6460 return auxL_error(L, auxL_EOPENSSL, "cipher.new"); 6466 return auxL_error(L, auxL_EOPENSSL, "cipher.new");
6461 6467
6462 return 1; 6468 return 1;