MDEV-20917 InnoDB is passing NULL to nonnull function parameters

mem_heap_dup(): Avoid mem_heap_alloc() and memcpy() of data=NULL, len=0.

trx_undo_report_insert_virtual(), trx_undo_page_report_insert(),
trx_undo_page_report_modify(): Avoid memcpy(ptr, NULL, 0).

dfield_data_is_binary_equal(): Correctly handle data=NULL, len=0.

rec_init_offsets_temp(): Do allow def_val=NULL in the interface.

This clean-up was motivated by WITH_UBSAN, and no bug related to this
was observed in the wild. It should be noted that undefined behaviour
such as memcpy(ptr, NULL, 0) could allow compilers to perform unsafe
optimizations, like it was the case in
commit fc168c3a5e (MDEV-15587).
This commit is contained in:
Marko Mäkelä 2019-10-29 18:20:32 +02:00
commit bef843b97f
6 changed files with 31 additions and 22 deletions

View file

@ -237,7 +237,10 @@ inline
void*
mem_heap_dup(mem_heap_t* heap, const void* data, size_t len)
{
return(memcpy(mem_heap_alloc(heap, len), data, len));
ut_ad(data || !len);
return UNIV_LIKELY(data != NULL)
? memcpy(mem_heap_alloc(heap, len), data, len)
: NULL;
}
/** Duplicate a NUL-terminated string, allocated from a memory heap.