summaryrefslogtreecommitdiff
path: root/sql/protocol.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-09-23 12:47:49 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-09-23 12:47:49 +0300
commit7c5519c12d46ead947d341cbdcbb6fbbe4d4fe1b (patch)
tree005b12e21b8c38e7bac3aca5042f1145e28acc30 /sql/protocol.cc
parent70960bd33d2699bc96821ec0a0381ca6de86e93e (diff)
downloadmariadb-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 'sql/protocol.cc')
-rw-r--r--sql/protocol.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/sql/protocol.cc b/sql/protocol.cc
index aa795b9d12a..de6d1b96f76 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates.
- Copyright (c) 2008, 2012, Monty Program Ab
+ Copyright (c) 2008, 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
@@ -58,7 +58,8 @@ bool Protocol_binary::net_store_data(const uchar *from, size_t length)
packet->realloc(packet_length+9+length))
return 1;
uchar *to= net_store_length((uchar*) packet->ptr()+packet_length, length);
- memcpy(to,from,length);
+ if (length)
+ memcpy(to,from,length);
packet->length((uint) (to+length-(uchar*) packet->ptr()));
return 0;
}
@@ -715,7 +716,8 @@ void net_send_progress_packet(THD *thd)
uchar *net_store_data(uchar *to, const uchar *from, size_t length)
{
to=net_store_length_fast(to,length);
- memcpy(to,from,length);
+ if (length)
+ memcpy(to,from,length);
return to+length;
}