Skip to content
Permalink
Browse files
MDEV-22387: Static_binary_string::q_append() invokes memcpy on NULL
Invoking memcpy() on a NULL pointer is undefined behaviour
(even if the length is 0) and gives the compiler permission to
assume that the pointer is nonnull. Recent versions of GCC
(starting with version 8) are more aggressively optimizing away
checks for NULL pointers. This undefined behaviour would cause
a SIGSEGV in the test main.func_encrypt on an optimized debug build
on GCC 10.2.0.
  • Loading branch information
dr-m committed Oct 30, 2020
1 parent 199863d commit cb253b8
Showing 1 changed file with 2 additions and 1 deletion.
@@ -313,7 +313,8 @@ class Static_binary_string : public Sql_alloc
}
void q_append(const char *data, size_t data_len)
{
memcpy(Ptr + str_length, data, data_len);
if (data_len)
memcpy(Ptr + str_length, data, data_len);
DBUG_ASSERT(str_length <= UINT_MAX32 - data_len);
str_length += (uint)data_len;
}

0 comments on commit cb253b8

Please sign in to comment.