diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-10-30 13:07:42 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-10-30 13:07:42 +0200 |
commit | cb253b8687092960287c333962d56771f6ad9db8 (patch) | |
tree | 68be7ea00ada38f699a65828a46c28105b9bc1db /sql/sql_string.h | |
parent | 199863d72b7cccaa4c75641c50c45a83b568ab8c (diff) | |
download | mariadb-git-cb253b8687092960287c333962d56771f6ad9db8.tar.gz |
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.
Diffstat (limited to 'sql/sql_string.h')
-rw-r--r-- | sql/sql_string.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/sql/sql_string.h b/sql/sql_string.h index 85c3bbd6044..0098ad15cb6 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -313,7 +313,8 @@ public: } 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; } |