diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-09-23 12:47:49 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-09-23 12:47:49 +0300 |
commit | 7c5519c12d46ead947d341cbdcbb6fbbe4d4fe1b (patch) | |
tree | 005b12e21b8c38e7bac3aca5042f1145e28acc30 /strings | |
parent | 70960bd33d2699bc96821ec0a0381ca6de86e93e (diff) | |
download | mariadb-git-7c5519c12d46ead947d341cbdcbb6fbbe4d4fe1b.tar.gz |
MDEV-22387: Do not violate __attribute__((nonnull))
Passing a null pointer to a nonnull argument is not only undefined
behaviour, but it also grants the compiler the permission to optimize
away further checks whether the pointer is null. GCC -O2 at least
starting with version 8 may do that, potentially causing SIGSEGV.
Diffstat (limited to 'strings')
-rw-r--r-- | strings/ctype-mb.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c index 3bcd29bbb8b..cabc940065b 100644 --- a/strings/ctype-mb.c +++ b/strings/ctype-mb.c @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2014, Oracle and/or its affiliates. - Copyright (c) 2009, 2014, SkySQL Ab. + Copyright (c) 2009, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -407,7 +407,9 @@ my_copy_fix_mb(CHARSET_INFO *cs, src, src + src_length, nchars, status); DBUG_ASSERT(well_formed_nchars <= nchars); - memmove(dst, src, (well_formed_length= status->m_source_end_pos - src)); + well_formed_length= status->m_source_end_pos - src; + if (well_formed_length) + memmove(dst, src, well_formed_length); if (!status->m_well_formed_error_pos) return well_formed_length; |