diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-09-03 09:05:56 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-09-03 09:05:56 +0300 |
commit | 94a520ddbe39ae97de1135d98699cf2674e6b77e (patch) | |
tree | 051dc62fd84edc150754dd826830d467b45074d8 /sql/net_serv.cc | |
parent | a256070e7d94fdd1d63a4823c638ff5c76ca9c73 (diff) | |
download | mariadb-git-94a520ddbe39ae97de1135d98699cf2674e6b77e.tar.gz |
MDEV-22387: Do not pass null pointer to some memcpy()
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.
These problems were caught in a WITH_UBSAN=ON build with the
Bug#7024 test in main.view.
Diffstat (limited to 'sql/net_serv.cc')
-rw-r--r-- | sql/net_serv.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/sql/net_serv.cc b/sql/net_serv.cc index ea5e4353c83..22eee6297c9 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2016, Oracle and/or its affiliates. - Copyright (c) 2012, 2017, MariaDB Corporation + Copyright (c) 2012, 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 @@ -577,7 +577,8 @@ net_write_buff(NET *net, const uchar *packet, ulong len) return net_real_write(net, packet, len) ? 1 : 0; /* Send out rest of the blocks as full sized blocks */ } - memcpy((char*) net->write_pos,packet,len); + if (len) + memcpy((char*) net->write_pos,packet,len); net->write_pos+= len; return 0; } |