Commit cb253b86 authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 199863d7
......@@ -313,6 +313,7 @@ class Static_binary_string : public Sql_alloc
}
void q_append(const char *data, size_t 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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment