From 0395af94682566913ca8acb4770043a204061dc5 Mon Sep 17 00:00:00 2001 From: Tobias Boege Date: Mon, 17 Nov 2014 13:35:14 +0000 Subject: [PATCH] [GB.OPENSSL] * BUG: Cipher: Fix memory leaks from returning strings. * BUG: Cipher[...].Encrypt() now passes the three mandatory arguments when creating a CipherText. git-svn-id: svn://localhost/gambas/trunk@6653 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.openssl/src/c_cipher.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gb.openssl/src/c_cipher.c b/gb.openssl/src/c_cipher.c index 2b97bcb87..5c637c032 100644 --- a/gb.openssl/src/c_cipher.c +++ b/gb.openssl/src/c_cipher.c @@ -179,7 +179,6 @@ static char *do_cipher(const unsigned char *data, unsigned int dlen, return out; __ERROR: - GB.FreeString(&out); return NULL; } @@ -228,10 +227,12 @@ BEGIN_METHOD(CipherMethod_Encrypt, GB_STRING plain; GB_STRING key; GB.Error("Encryption failed"); return; } - res = GB.New(GB.FindClass("CipherText"), NULL, NULL); - res->cipher = cipher; - res->key = GB.NewString((char *) key, sizeof(key)); - res->iv = GB.NewString((char *) iv, sizeof(iv)); + + GB.Push(3, GB_T_STRING, cipher, length, + GB_T_STRING, key, sizeof(key), + GB_T_STRING, iv, sizeof(iv)); + res = GB.New(GB.FindClass("CipherText"), NULL, (void*)(intptr_t) 3); + GB.FreeString(&cipher); GB.ReturnObject(res); END_METHOD @@ -243,7 +244,7 @@ BEGIN_METHOD(CipherMethod_Decrypt, GB_OBJECT ciph) CCIPHERTEXT *ciph = VARG(ciph); unsigned int length; - char *plain, *res; + char *plain; plain = do_cipher((uchar *) ciph->cipher, GB.StringLength(ciph->cipher), @@ -253,10 +254,9 @@ BEGIN_METHOD(CipherMethod_Decrypt, GB_OBJECT ciph) GB.Error("Decryption failed"); return; } - res = GB.NewString(plain, length); - GB.ReturnString(res); + GB.ReturnString(plain); GB.ReturnBorrow(); - GB.FreeString(&res); + GB.FreeString(&plain); GB.ReturnRelease(); END_METHOD @@ -308,6 +308,7 @@ BEGIN_METHOD(CipherMethod_EncryptSalted, GB_STRING plain; GB_STRING passwd; res = GB.NewZeroString("Salted__"); res = GB.AddString(res, (char *) salt, sizeof(salt)); res = GB.AddString(res, cipher, length); + GB.FreeString(&cipher); GB.ReturnString(res); GB.ReturnBorrow(); GB.FreeString(&res); @@ -324,7 +325,7 @@ BEGIN_METHOD(CipherMethod_DecryptSalted, GB_STRING cipher; GB_STRING passwd) unsigned char key[EVP_CIPHER_key_length(_method)]; unsigned char iv[EVP_CIPHER_iv_length(_method)]; unsigned int clen, length; - char *plain, *res; + char *plain; if (!strstr(STRING(cipher), "Salted__")) { GB.Error("Unrecognised cipher string format"); @@ -342,10 +343,9 @@ BEGIN_METHOD(CipherMethod_DecryptSalted, GB_STRING cipher; GB_STRING passwd) GB.Error("Decryption failed"); return; } - res = GB.NewString(plain, length); - GB.ReturnString(res); + GB.ReturnString(plain); GB.ReturnBorrow(); - GB.FreeString(&res); + GB.FreeString(&plain); GB.ReturnRelease(); END_METHOD