aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar William Ahern <william@25thandClement.com> 2015-12-17 17:42:03 +0800
committerLibravatarLibravatar William 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) {
static int cipher_new(lua_State *L) {
const EVP_CIPHER *type;
EVP_CIPHER_CTX *ctx;
+ unsigned char key[EVP_MAX_KEY_LENGTH] = { 0 };
type = cipher_checktype(L, 1);
ctx = prepudata(L, sizeof *ctx, CIPHER_CLASS, NULL);
EVP_CIPHER_CTX_init(ctx);
- if (!EVP_CipherInit_ex(ctx, type, NULL, NULL, NULL, -1))
+ /*
+ * NOTE: For some ciphers like AES calling :update or :final without
+ * setting a key causes a SEGV. Set a dummy key here. Same solution
+ * as used by Ruby OSSL.
+ */
+ if (!EVP_CipherInit_ex(ctx, type, NULL, key, NULL, -1))
return auxL_error(L, auxL_EOPENSSL, "cipher.new");
return 1;