Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix UB and possible exception trigger #3025

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix UB and possible exception trigger #3025

wants to merge 1 commit into from

Conversation

scaprile
Copy link
Collaborator

@scaprile scaprile commented Jan 28, 2025

ASAN was reporting undefined behaviour (UB).

src/net_builtin.c:655:37: runtime error: applying zero offset to null pointer

Weird as it seems, &io->buf[io->len] is UB in C and in C++ < C++17 for a NULL pointer, even if the offset is 0. This condition happens at TLS receive start time, when TLS has not yet decrypted any record and hence no iobuf has been created for decrypted data.

Once this is fixed by eliminating the offset when the pointer is NULL, then the first time a record gets decrypted there is no buffer to hold data, it will be created at the next loop. when mg_tls_avail() will be called. We then pass a NULL destination pointer to memmove(), which, even though len is 0, will violate the specs and trigger ASAN again

src/tls_builtin.c:1385:11: runtime error: null pointer passed as argument 1, which is declared to never be null
/usr/include/string.h:48:14: note: nonnull attribute specified here

So, now we just return 0 when either the buffer pointer is NULL or buffer length is 0

@scaprile scaprile requested review from cpq and robertc2000 January 28, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants