fix UB and possible exception trigger #3025
Open
+4
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ASAN was reporting undefined behaviour (UB).
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 tomemmove()
, which, even though len is 0, will violate the specs and trigger ASAN againSo, now we just return 0 when either the buffer pointer is NULL or buffer length is 0