Commit 7c5519c1 authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 70960bd3
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. /* 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 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 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) ...@@ -58,7 +58,8 @@ bool Protocol_binary::net_store_data(const uchar *from, size_t length)
packet->realloc(packet_length+9+length)) packet->realloc(packet_length+9+length))
return 1; return 1;
uchar *to= net_store_length((uchar*) packet->ptr()+packet_length, length); 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())); packet->length((uint) (to+length-(uchar*) packet->ptr()));
return 0; return 0;
} }
...@@ -715,7 +716,8 @@ void net_send_progress_packet(THD *thd) ...@@ -715,7 +716,8 @@ void net_send_progress_packet(THD *thd)
uchar *net_store_data(uchar *to, const uchar *from, size_t length) uchar *net_store_data(uchar *to, const uchar *from, size_t length)
{ {
to=net_store_length_fast(to,length); to=net_store_length_fast(to,length);
memcpy(to,from,length); if (length)
memcpy(to,from,length);
return to+length; return to+length;
} }
......
...@@ -826,7 +826,7 @@ int sortcmp(const String *s,const String *t, CHARSET_INFO *cs) ...@@ -826,7 +826,7 @@ int sortcmp(const String *s,const String *t, CHARSET_INFO *cs)
int stringcmp(const String *s,const String *t) int stringcmp(const String *s,const String *t)
{ {
uint32 s_len=s->length(),t_len=t->length(),len=MY_MIN(s_len,t_len); uint32 s_len=s->length(),t_len=t->length(),len=MY_MIN(s_len,t_len);
int cmp= memcmp(s->ptr(), t->ptr(), len); int cmp= len ? memcmp(s->ptr(), t->ptr(), len) : 0;
return (cmp) ? cmp : (int) (s_len - t_len); return (cmp) ? cmp : (int) (s_len - t_len);
} }
......
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. /* 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 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 it under the terms of the GNU General Public License as published by
...@@ -407,7 +407,9 @@ my_copy_fix_mb(CHARSET_INFO *cs, ...@@ -407,7 +407,9 @@ my_copy_fix_mb(CHARSET_INFO *cs,
src, src + src_length, src, src + src_length,
nchars, status); nchars, status);
DBUG_ASSERT(well_formed_nchars <= nchars); 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) if (!status->m_well_formed_error_pos)
return well_formed_length; return well_formed_length;
......
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