簡體   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