summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc8
-rw-r--r--sql/handler.h6
-rw-r--r--sql/item_func.cc3
-rw-r--r--sql/item_sum.cc14
-rw-r--r--sql/lex_string.h6
-rw-r--r--sql/mf_iocache_encr.cc15
-rw-r--r--sql/opt_range.cc107
-rw-r--r--sql/opt_split.cc12
-rw-r--r--sql/sql_acl.cc12
-rw-r--r--sql/sql_class.cc3
-rw-r--r--sql/sql_join_cache.cc3
-rw-r--r--sql/sql_lex.cc3
-rw-r--r--sql/sql_prepare.cc22
-rw-r--r--sql/sql_select.cc6
-rw-r--r--sql/sql_string.cc9
-rw-r--r--sql/table.h3
-rw-r--r--sql/unireg.cc7
-rw-r--r--sql/unireg.h3
18 files changed, 201 insertions, 41 deletions
diff --git a/sql/field.cc b/sql/field.cc
index f8d9cbf93ce..fe3aebce05d 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -8724,7 +8724,10 @@ int Field_blob::cmp_binary(const uchar *a_ptr, const uchar *b_ptr,
b_length=get_length(b_ptr);
if (b_length > max_length)
b_length=max_length;
- diff=memcmp(a,b,MY_MIN(a_length,b_length));
+ if (uint32 len= MY_MIN(a_length,b_length))
+ diff= memcmp(a,b,len);
+ else
+ diff= 0;
return diff ? diff : (int) (a_length - b_length);
}
@@ -8751,7 +8754,8 @@ uint Field_blob::get_key_image_itRAW(const uchar *ptr_arg, uchar *buff,
length=(uint) blob_length;
}
int2store(buff,length);
- memcpy(buff+HA_KEY_BLOB_LENGTH, blob, length);
+ if (length)
+ memcpy(buff+HA_KEY_BLOB_LENGTH, blob, length);
return HA_KEY_BLOB_LENGTH+length;
}
diff --git a/sql/handler.h b/sql/handler.h
index e06b6a7aa43..41da458aa2a 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -866,8 +866,10 @@ struct xid_t {
void set(long f, const char *g, long gl, const char *b, long bl)
{
formatID= f;
- memcpy(data, g, gtrid_length= gl);
- memcpy(data+gl, b, bqual_length= bl);
+ if ((gtrid_length= gl))
+ memcpy(data, g, gl);
+ if ((bqual_length= bl))
+ memcpy(data+gl, b, bl);
}
void set(ulonglong xid)
{
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 027488e0279..e133fead665 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -4894,7 +4894,8 @@ update_hash(user_var_entry *entry, bool set_null, void *ptr, size_t length,
length--; // Fix length change above
entry->value[length]= 0; // Store end \0
}
- memmove(entry->value, ptr, length);
+ if (length)
+ memmove(entry->value, ptr, length);
if (type == DECIMAL_RESULT)
((my_decimal*)entry->value)->fix_buffer_pointer();
entry->length= length;
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 4a94169c6f8..5d0578df4ac 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
- Copyright (c) 2008, 2015, MariaDB
+ Copyright (c) 2008, 2020, MariaDB
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
@@ -473,7 +473,8 @@ Item_sum::Item_sum(THD *thd, Item_sum *item):
if (!(orig_args= (Item**) thd->alloc(sizeof(Item*)*arg_count)))
return;
}
- memcpy(orig_args, item->orig_args, sizeof(Item*)*arg_count);
+ if (arg_count)
+ memcpy(orig_args, item->orig_args, sizeof(Item*)*arg_count);
init_aggregator();
with_distinct= item->with_distinct;
if (item->aggr)
@@ -1132,7 +1133,8 @@ Item_sum_num::fix_fields(THD *thd, Item **ref)
check_sum_func(thd, ref))
return TRUE;
- memcpy (orig_args, args, sizeof (Item *) * arg_count);
+ if (arg_count)
+ memcpy (orig_args, args, sizeof (Item *) * arg_count);
fixed= 1;
return FALSE;
}
@@ -1365,7 +1367,8 @@ Item_sum_sp::fix_fields(THD *thd, Item **ref)
if (check_sum_func(thd, ref))
return TRUE;
- memcpy(orig_args, args, sizeof(Item *) * arg_count);
+ if (arg_count)
+ memcpy(orig_args, args, sizeof(Item *) * arg_count);
fixed= 1;
return FALSE;
}
@@ -3928,7 +3931,8 @@ Item_func_group_concat(THD *thd, Name_resolution_context *context_arg,
/* orig_args is only used for print() */
orig_args= (Item**) (order + arg_count_order);
- memcpy(orig_args, args, sizeof(Item*) * arg_count);
+ if (arg_count)
+ memcpy(orig_args, args, sizeof(Item*) * arg_count);
if (limit_clause)
{
row_limit= row_limit_arg;
diff --git a/sql/lex_string.h b/sql/lex_string.h
index 008e5f75812..e7a732346c4 100644
--- a/sql/lex_string.h
+++ b/sql/lex_string.h
@@ -76,12 +76,12 @@ static inline bool lex_string_cmp(CHARSET_INFO *charset, const LEX_CSTRING *a,
static inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b)
{
- return (a->length != b->length ||
- memcmp(a->str, b->str, a->length));
+ return a->length != b->length ||
+ (a->length && memcmp(a->str, b->str, a->length));
}
static inline bool cmp(const LEX_CSTRING a, const LEX_CSTRING b)
{
- return a.length != b.length || memcmp(a.str, b.str, a.length);
+ return a.length != b.length || (a.length && memcmp(a.str, b.str, a.length));
}
/*
diff --git a/sql/mf_iocache_encr.cc b/sql/mf_iocache_encr.cc
index 072c0a48269..63830ec620a 100644
--- a/sql/mf_iocache_encr.cc
+++ b/sql/mf_iocache_encr.cc
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2015, MariaDB
+ Copyright (c) 2015, 2020, MariaDB
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
@@ -85,7 +85,6 @@ static int my_b_encr_read(IO_CACHE *info, uchar *Buffer, size_t Count)
do
{
- size_t copied;
uint elength, wlength, length;
uchar iv[MY_AES_BLOCK_SIZE]= {0};
@@ -116,11 +115,13 @@ static int my_b_encr_read(IO_CACHE *info, uchar *Buffer, size_t Count)
DBUG_ASSERT(length <= info->buffer_length);
- copied= MY_MIN(Count, (size_t)(length - pos_offset));
-
- memcpy(Buffer, info->buffer + pos_offset, copied);
- Count-= copied;
- Buffer+= copied;
+ size_t copied= MY_MIN(Count, (size_t)(length - pos_offset));
+ if (copied)
+ {
+ memcpy(Buffer, info->buffer + pos_offset, copied);
+ Count-= copied;
+ Buffer+= copied;
+ }
info->read_pos= info->buffer + pos_offset + copied;
info->read_end= info->buffer + length;
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index c13563f9263..adc0572cb1c 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -15643,6 +15643,113 @@ static void print_ror_scans_arr(TABLE *table, const char *msg,
DBUG_VOID_RETURN;
}
+static String dbug_print_sel_arg_buf;
+
+static void
+print_sel_arg_key(Field *field, const uchar *key, String *out)
+{
+ TABLE *table= field->table;
+ my_bitmap_map *old_sets[2];
+ dbug_tmp_use_all_columns(table, old_sets, table->read_set, table->write_set);
+
+ if (field->real_maybe_null())
+ {
+ if (*key)
+ {
+ out->append("NULL");
+ goto end;
+ }
+ key++; // Skip null byte
+ }
+
+ field->set_key_image(key, field->pack_length());
+
+ if (field->type() == MYSQL_TYPE_BIT)
+ (void) field->val_int_as_str(out, 1);
+ else
+ field->val_str(out);
+
+end:
+ dbug_tmp_restore_column_maps(table->read_set, table->write_set, old_sets);
+}
+
+
+/*
+ @brief
+ Produce a string representation of an individual SEL_ARG and return pointer
+ to it
+
+ @detail
+ Intended usage:
+
+ (gdb) p dbug_print_sel_arg(ptr)
+*/
+
+const char *dbug_print_sel_arg(SEL_ARG *sel_arg)
+{
+ StringBuffer<64> buf;
+ String &out= dbug_print_sel_arg_buf;
+ out.length(0);
+
+ if (!sel_arg)
+ {
+ out.append("NULL");
+ goto end;
+ }
+
+ out.append("SEL_ARG(");
+
+ const char *stype;
+ switch(sel_arg->type) {
+ case SEL_ARG::IMPOSSIBLE:
+ stype="IMPOSSIBLE";
+ break;
+ case SEL_ARG::MAYBE:
+ stype="MAYBE";
+ break;
+ case SEL_ARG::MAYBE_KEY:
+ stype="MAYBE_KEY";
+ break;
+ case SEL_ARG::KEY_RANGE:
+ default:
+ stype= NULL;
+ }
+
+ if (stype)
+ {
+ out.append("type=");
+ out.append(stype);
+ goto end;
+ }
+
+ if (sel_arg->min_flag & NO_MIN_RANGE)
+ out.append("-inf");
+ else
+ {
+ print_sel_arg_key(sel_arg->field, sel_arg->min_value, &buf);
+ out.append(buf);
+ }
+
+ out.append((sel_arg->min_flag & NEAR_MIN)? "<" : "<=");
+
+ out.append(sel_arg->field->field_name);
+
+ out.append((sel_arg->max_flag & NEAR_MAX)? "<" : "<=");
+
+ if (sel_arg->max_flag & NO_MAX_RANGE)
+ out.append("+inf");
+ else
+ {
+ print_sel_arg_key(sel_arg->field, sel_arg->max_value, &buf);
+ out.append(buf);
+ }
+
+ out.append(")");
+
+end:
+ return dbug_print_sel_arg_buf.c_ptr_safe();
+}
+
/*****************************************************************************
** Print a quick range for debugging
diff --git a/sql/opt_split.cc b/sql/opt_split.cc
index a6031f75a5b..3a086aef04c 100644
--- a/sql/opt_split.cc
+++ b/sql/opt_split.cc
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2017 MariaDB
+ Copyright (c) 2017, 2020, MariaDB
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
@@ -749,13 +749,13 @@ void JOIN::add_keyuses_for_splitting()
if (allocate_dynamic(&keyuse, save_qep->keyuse.elements + added_keyuse_count))
goto err;
- memcpy(keyuse.buffer,
- save_qep->keyuse.buffer,
- (size_t) save_qep->keyuse.elements * keyuse.size_of_element);
- keyuse.elements= save_qep->keyuse.elements;
+ idx= keyuse.elements= save_qep->keyuse.elements;
+ if (keyuse.elements)
+ memcpy(keyuse.buffer,
+ save_qep->keyuse.buffer,
+ (size_t) keyuse.elements * keyuse.size_of_element);
keyuse_ext= &ext_keyuses_for_splitting->at(0);
- idx= save_qep->keyuse.elements;
for (i=0; i < added_keyuse_count; i++, keyuse_ext++, idx++)
{
set_dynamic(&keyuse, (KEYUSE *) keyuse_ext, idx);
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 2c96e0e9ff2..ef96e8f2484 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -14536,7 +14536,7 @@ static int native_password_authenticate(MYSQL_PLUGIN_VIO *vio,
info->password_used= PASSWORD_USED_YES;
if (pkt_len == SCRAMBLE_LENGTH)
{
- if (!info->auth_string_length)
+ if (info->auth_string_length != SCRAMBLE_LENGTH)
DBUG_RETURN(CR_AUTH_USER_CREDENTIALS);
if (check_scramble(pkt, thd->scramble, (uchar*)info->auth_string))
@@ -14563,9 +14563,13 @@ static int native_password_make_scramble(const char *password,
return 0;
}
+/* As this contains is a string of not a valid SCRAMBLE_LENGTH */
+static const char invalid_password[] = "*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE";
+
static int native_password_get_salt(const char *hash, size_t hash_length,
unsigned char *out, size_t *out_length)
{
+ DBUG_ASSERT(sizeof(invalid_password) > SCRAMBLE_LENGTH);
DBUG_ASSERT(*out_length >= SCRAMBLE_LENGTH);
if (hash_length == 0)
{
@@ -14575,6 +14579,12 @@ static int native_password_get_salt(const char *hash, size_t hash_length,
if (hash_length != SCRAMBLED_PASSWORD_CHAR_LENGTH)
{
+ if (hash_length == 7 && strcmp(hash, "invalid") == 0)
+ {
+ memcpy(out, invalid_password, SCRAMBLED_PASSWORD_CHAR_LENGTH);
+ *out_length= SCRAMBLED_PASSWORD_CHAR_LENGTH;
+ return 0;
+ }
my_error(ER_PASSWD_LENGTH, MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH);
return 1;
}
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 6011dbbc6dd..a4fd26cf7d8 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -4982,7 +4982,8 @@ extern "C" size_t thd_query_safe(MYSQL_THD thd, char *buf, size_t buflen)
if (!mysql_mutex_trylock(&thd->LOCK_thd_data))
{
len= MY_MIN(buflen - 1, thd->query_length());
- memcpy(buf, thd->query(), len);
+ if (len)
+ memcpy(buf, thd->query(), len);
mysql_mutex_unlock(&thd->LOCK_thd_data);
}
buf[len]= '\0';
diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc
index 5a243cd0a6d..4b879293fdb 100644
--- a/sql/sql_join_cache.cc
+++ b/sql/sql_join_cache.cc
@@ -1397,7 +1397,8 @@ uint JOIN_CACHE::write_record_data(uchar * link, bool *is_full)
blob_field->get_image(cp, copy->length,
blob_field->charset());
DBUG_ASSERT(cp + copy->length + copy->blob_length <= buff + buff_size);
- memcpy(cp+copy->length, copy->str, copy->blob_length);
+ if (copy->blob_length)
+ memcpy(cp+copy->length, copy->str, copy->blob_length);
cp+= copy->length+copy->blob_length;
}
break;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 61e3b89c9a3..60a7a4f6ce0 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -10209,7 +10209,8 @@ bool LEX::new_sp_instr_stmt(THD *thd,
qbuff.length= prefix.length + suffix.length;
if (!(qbuff.str= (char*) alloc_root(thd->mem_root, qbuff.length + 1)))
return true;
- memcpy(qbuff.str, prefix.str, prefix.length);
+ if (prefix.length)
+ memcpy(qbuff.str, prefix.str, prefix.length);
strmake(qbuff.str + prefix.length, suffix.str, suffix.length);
i->m_query= qbuff;
return sphead->add_instr(i);
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 531d639d6f4..184540b7aa9 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2002, 2015, Oracle and/or its affiliates.
- Copyright (c) 2008, 2019, MariaDB
+ Copyright (c) 2008, 2020, MariaDB
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
@@ -122,7 +122,10 @@ When one supplies long data for a placeholder:
#include "sql_handler.h"
#include "transaction.h" // trans_rollback_implicit
#include "mysql/psi/mysql_ps.h" // MYSQL_EXECUTE_PS
+#ifdef WITH_WSREP
#include "wsrep_mysqld.h"
+#include "wsrep_trans_observer.h"
+#endif /* WITH_WSREP */
/* Constants defining bits in parameter type flags. Flags are read from high byte of short value */
static const uint PARAMETER_FLAG_UNSIGNED = 128U << 8;
@@ -4607,6 +4610,23 @@ reexecute:
thd->m_reprepare_observer= NULL;
+#ifdef WITH_WSREP
+ if (!(sql_command_flags[lex->sql_command] & CF_PS_ARRAY_BINDING_OPTIMIZED) &&
+ WSREP(thd))
+ {
+ if (wsrep_after_statement(thd))
+ {
+ /*
+ Re-execution success is unlikely after an error from
+ wsrep_after_statement(), so retrun error immediately.
+ */
+ thd->get_stmt_da()->reset_diagnostics_area();
+ wsrep_override_error(thd, thd->wsrep_cs().current_error(),
+ thd->wsrep_cs().current_error_status());
+ }
+ }
+ else
+#endif /* WITH_WSREP */
if (unlikely(error) &&
(sql_command_flags[lex->sql_command] & CF_REEXECUTION_FRAGILE) &&
!thd->is_fatal_error && !thd->killed &&
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 2a856a0d51f..6071fe10929 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -27984,10 +27984,10 @@ JOIN::reoptimize(Item *added_where, table_map join_tables,
if (save_to)
{
DBUG_ASSERT(!keyuse.elements);
- memcpy(keyuse.buffer,
- save_to->keyuse.buffer,
- (size_t) save_to->keyuse.elements * keyuse.size_of_element);
keyuse.elements= save_to->keyuse.elements;
+ if (size_t e= keyuse.elements)
+ memcpy(keyuse.buffer,
+ save_to->keyuse.buffer, e * keyuse.size_of_element);
}
/* Add the new access methods to the keyuse array. */
diff --git a/sql/sql_string.cc b/sql/sql_string.cc
index 94f2e6fc8c6..f2a0f55aec8 100644
--- a/sql/sql_string.cc
+++ b/sql/sql_string.cc
@@ -237,8 +237,8 @@ bool Binary_string::copy(const Binary_string &str)
{
if (alloc(str.str_length))
return TRUE;
- str_length=str.str_length;
- bmove(Ptr,str.Ptr,str_length); // May be overlapping
+ if ((str_length=str.str_length))
+ bmove(Ptr,str.Ptr,str_length); // May be overlapping
Ptr[str_length]=0;
return FALSE;
}
@@ -574,8 +574,11 @@ bool Binary_string::append_ulonglong(ulonglong val)
bool String::append(const char *s, size_t arg_length, CHARSET_INFO *cs)
{
+ if (!arg_length)
+ return false;
+
uint32 offset;
-
+
if (needs_conversion((uint32)arg_length, cs, charset(), &offset))
{
size_t add_length;
diff --git a/sql/table.h b/sql/table.h
index ec865f2e3ce..83e8b69b5e3 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -3194,7 +3194,8 @@ inline void mark_as_null_row(TABLE *table)
{
table->null_row=1;
table->status|=STATUS_NULL_ROW;
- bfill(table->null_flags,table->s->null_bytes,255);
+ if (table->s->null_bytes)
+ bfill(table->null_flags,table->s->null_bytes,255);
}
bool is_simple_order(ORDER *order);
diff --git a/sql/unireg.cc b/sql/unireg.cc
index c299549843f..ecd5bb8d430 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -1104,8 +1104,11 @@ static bool pack_fields(uchar **buff_arg, List<Create_field> &create_fields,
it.rewind();
while ((field=it++))
{
- memcpy(buff, field->comment.str, field->comment.length);
- buff+= field->comment.length;
+ if (size_t l= field->comment.length)
+ {
+ memcpy(buff, field->comment.str, l);
+ buff+= l;
+ }
}
}
*buff_arg= buff;
diff --git a/sql/unireg.h b/sql/unireg.h
index 873d6f681fc..dbff9ff77f8 100644
--- a/sql/unireg.h
+++ b/sql/unireg.h
@@ -76,7 +76,8 @@
#define cmp_record(A,B) memcmp((A)->record[0],(A)->B,(size_t) (A)->s->reclength)
#define empty_record(A) { \
restore_record((A),s->default_values); \
- bfill((A)->null_flags,(A)->s->null_bytes,255);\
+ if ((A)->s->null_bytes) \
+ bfill((A)->null_flags,(A)->s->null_bytes,255); \
}
/* Defines for use with openfrm, openprt and openfrd */