繁体   English   中英

内核资源泄漏BIO_do_connect

[英]Kernel Resource Leak BIO_do_connect

我需要提供以下帮助: 我试图寻找答案,却一直被问到。

Inspector XE给出了以下结果:内核资源泄漏在线

he=BIO_gethostbyname(str);

这行是OpenSSL源代码的一部分,我无法想象这里有什么错误。

此函数在内部称为:

BIO_do_connect();

我的代码是。

bio = BIO_new_connect(...);
if (BIO_do_connect(bio) != 1) { ... }
...
if (BIO_free(bio) != 0) { ... }

连接成功,当我与线程并发调用1000次此函数时,只会发生唯一的错误。

这个程序真的会导致内核资源泄漏吗?

BIO_gethostbyname不是(不能)是线程安全的,因为它返回指向静态缓冲区的指针。 确实,openssl的bio.h中提到了这一点,请阅读

struct hostent *BIO_gethostbyname(const char *name);
/* We might want a thread-safe interface too:
 * struct hostent *BIO_gethostbyname_r(const char *name,
 *     struct hostent *result, void *buffer, size_t buflen);
 * or something similar (caller allocates a struct hostent,
 * pointed to by "result", and additional buffer space for the various
 * substructures; if the buffer does not suffice, NULL is returned
 * and an appropriate error code is set).
 */

...但是,到目前为止,还没有实现BIO_gethostbyname_r函数,无论如何,如果有的话,而BIO_do_connect没有使用它,它将无济于事。

但是绝望没有! 此函数调用周围有锁定代码,因此可以(可能)使它起作用。 不过,有趣的是-锁定代码并不总是做任何事情。 我假设您没有使用OPENSSL_NO_LOCKING编译OpenSSL,因为它不是默认值,并且我无法想象有人将其放入如果要开发多线程应用程序的情况,所以我猜您忘记了调用

CRYPTO_thread_setup();

在生成使用OpenSSL的线程之前。 这很重要的原因是, CRYPTO_thread_setup确实将函数指针设置为处理实际锁定的平台相关函数。 如果未调用CRYPTO_thread_setup ,则此指针将保持NULL ,并且CRYPTO_lockBIO_gethostbyname调用周围使用的宏底部的相关函数)将无提示地执行任何操作。 据我所知,还没有任何您可能知道的文档。

可能会说您对OpenSSL代码库质量的乐观态度放错了地方。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM