Memory leak in OpenSSL function EVP_EncryptFinal_ex

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

I implemented encryption procedure based on the tutorial:

http://www.openssl.org/docs/crypto/EVP_EncryptInit.html#

When I run it trough valgring and got the following report:

==2371== 176 bytes in 1 blocks are still reachable in loss record 3 of 6 ==2371==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64- linux.so) ==2371==    by 0x56CA133: CRYPTO_malloc (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0) ==2371==    by 0x575280F: lh_new (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0) ==2371==    by 0x5754D4F: ??? (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0) ==2371==    by 0x575503E: ??? (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0) ==2371==    by 0x5755A1D: ERR_get_state (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0) ==2371==    by 0x5755E5E: ERR_put_error (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0) ==2371==    by 0x5757E38: EVP_DecryptFinal_ex (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0) ==2371==    by 0x46DA2A: unmangleUrl(std::string const&, std::string const&, std::string const&) (mangle_url.cpp:84) ==2371==    by 0x46621C: main (main.cpp:348)

I downloaded source code of OpenSSL. Inside ERR_put_error I see memory allocation in ERR_get_state, and releasing memory inside err_clear_data, but accruing the logic inside err_clear_data. It got release only if flag ERR_TXT_MALLOCED, and I do not see who is raising the flag.

What I am doing wrong?

I am using Ubuntu 12.04

$ cat /etc/issue Ubuntu 12.04.2 LTS \n \l

And OpenSSL version is

$ openssl version OpenSSL 1.0.1 14 Mar 2012

My code snippet mangle_url.cpp:

std::string unmangleUrl(const std::string &key, const std::string &iv, const std::string &url) {     std::string binUrl = hexToBin(url);     std::string res;     res.resize(binUrl.size() * 2);     EVP_CIPHER_CTX ctx;     EVP_CIPHER_CTX_init(&ctx);     EVP_DecryptInit_ex(&ctx, EVP_bf_cbc(), NULL, (const unsigned char *)&key[0], (const unsigned char *)&iv[        
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!