20240718-BIO_DGRAM-memory-leak#7760
Conversation
d6b4313 to
0582de7
Compare
0582de7 to
63d6f11
Compare
|
retest this please |
wolfssl/ssl.h
Outdated
| WOLFSSL_API WOLFSSL_BIO_METHOD* wolfSSL_BIO_f_ssl(void); | ||
| WOLFSSL_API WOLFSSL_BIO* wolfSSL_BIO_new_socket(int sfd, int flag); | ||
| WOLFSSL_API WOLFSSL_BIO* wolfSSL_BIO_new_dgram(int fd, int closeF); | ||
| WOLFSSL_API WOLFSSL_BIO* wolfSSL_BIO_new_socket(SOCKET_T sfd, int flag); |
There was a problem hiding this comment.
Changing public API. And it doesn't match OpenSSL. (Yes OpenSSL is wrong.)
Make a new one that is SOCKET_T is my suggestion.
There was a problem hiding this comment.
not bothering with the new APIs for now -- may not in practice ever be needed.
in any case I've reverted all the changes to public APIs. now, all substantive header changes in the PR are in internal.h.
wolfssl/internal.h
Outdated
| int rdIdx; /* current read index */ | ||
| int readRq; /* read request */ | ||
| int num; /* socket num or length */ | ||
| SOCKET_T num; /* socket num or length */ |
There was a problem hiding this comment.
Any reason we have to use num for socket?
There was a problem hiding this comment.
num is used for the size in some BIO's and the file descriptors too. Not sure if SOCKET_T is the correct type to use for that. I would remove num and create new members for each use case to make it easier to identify what needs fixing.
There was a problem hiding this comment.
after comparing notes with Juliusz, I've opted to refactor .num, and .ptr for completeness, as unions. it looks very nice now.
src/bio.c
Outdated
| * @return New BIO object or NULL on failure | ||
| */ | ||
| WOLFSSL_BIO *wolfSSL_BIO_new_fd(int fd, int close_flag) | ||
| WOLFSSL_BIO *wolfSSL_BIO_new_fd(SOCKET_T fd, int close_flag) |
There was a problem hiding this comment.
OpenSSL API takes int. Leave it as is and cast inside.
src/bio.c
Outdated
|
|
||
|
|
||
| WOLFSSL_BIO* wolfSSL_BIO_new_socket(int sfd, int closeF) | ||
| WOLFSSL_BIO* wolfSSL_BIO_new_socket(SOCKET_T sfd, int closeF) |
src/bio.c
Outdated
|
|
||
|
|
||
| WOLFSSL_BIO* wolfSSL_BIO_new_dgram(int fd, int closeF) | ||
| WOLFSSL_BIO* wolfSSL_BIO_new_dgram(SOCKET_T fd, int closeF) |
src/bio.c
Outdated
|
|
||
| #ifndef NO_FILESYSTEM | ||
| long wolfSSL_BIO_set_fd(WOLFSSL_BIO* b, int fd, int closeF) | ||
| long wolfSSL_BIO_set_fd(WOLFSSL_BIO* b, SOCKET_T fd, int closeF) |
src/bio.c
Outdated
| } | ||
|
|
||
| int wolfSSL_BIO_get_fd(WOLFSSL_BIO *bio, int* fd) | ||
| SOCKET_T wolfSSL_BIO_get_fd(WOLFSSL_BIO *bio, SOCKET_T* fd) |
wolfssl/internal.h
Outdated
| int rdIdx; /* current read index */ | ||
| int readRq; /* read request */ | ||
| int num; /* socket num or length */ | ||
| SOCKET_T num; /* socket num or length */ |
There was a problem hiding this comment.
num is used for the size in some BIO's and the file descriptors too. Not sure if SOCKET_T is the correct type to use for that. I would remove num and create new members for each use case to make it easier to identify what needs fixing.
63d6f11 to
3192d19
Compare
3192d19 to
3d26fd2
Compare
* refactor WOLFSSL_BIO.num and WOLFSSL_BIO.ptr as unions, for clarity and bug resistance (no functional changes). * in wolfSSL_BIO_free(), add WOLFSSL_BIO_DGRAM to the test for closing bio->num.fd, fixing a descriptor leak. * use SOCKET_INVALID consistently as the invalid value for WOLFSSL_BIO.num.fd, and use SOCKET_T consistently as the internal type for file descriptors. * move the definitions for SOCKET_T and SOCKET_INVALID from wolfio.h to the filesystem section of wc_port.h, and allow override definitions of SOCKET_T. detected and tested with wolfssl-multi-test.sh ... pq-hybrid-all-rpk-valgrind-unittest. also tested with wolfssl-multi-test.sh ... super-quick-check.
3d26fd2 to
787397b
Compare
src/bio.cand related:refactor
WOLFSSL_BIO.numandWOLFSSL_BIO.ptras unions, for clarity and bug resistance (no functional changes).in
wolfSSL_BIO_free(), addWOLFSSL_BIO_DGRAMto the test for closingbio->num.fd, fixing a descriptor leak.use
SOCKET_INVALIDconsistently as the invalid value forWOLFSSL_BIO.num.fd, and useSOCKET_Tconsistently as the internal type for file descriptors.move the definitions for
SOCKET_TandSOCKET_INVALIDfromwolfio.hto the filesystem section ofwc_port.h, and allow override definitions ofSOCKET_T.detected and tested with
wolfssl-multi-test.sh ... pq-hybrid-all-rpk-valgrind-unittest. also tested withwolfssl-multi-test.sh ... super-quick-check.