diff options
author | Alexander Barkov <bar@mariadb.org> | 2017-11-20 09:33:19 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2017-11-20 09:33:19 +0400 |
commit | 9b53e541f03d74e2777e0d1e7618b6246b81c721 (patch) | |
tree | 669b60056a43fb77f6823c795ed5f8d221623411 /sql | |
parent | c44ece7342f14498630e4ab403ae125971137457 (diff) | |
download | mariadb-git-9b53e541f03d74e2777e0d1e7618b6246b81c721.tar.gz |
MDEV-13788 Server crash when issuing bad SQL partition syntax
Diffstat (limited to 'sql')
-rw-r--r-- | sql/partition_info.cc | 20 | ||||
-rw-r--r-- | sql/partition_info.h | 1 | ||||
-rw-r--r-- | sql/sql_partition.cc | 11 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 14 |
4 files changed, 26 insertions, 20 deletions
diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 512bf296135..740e5087477 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -2132,6 +2132,24 @@ end: DBUG_RETURN(result); } + +bool partition_info::error_if_requires_values() const +{ + switch (part_type) { + case NOT_A_PARTITION: + case HASH_PARTITION: + break; + case RANGE_PARTITION: + my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), "RANGE", "LESS THAN"); + return true; + case LIST_PARTITION: + my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), "LIST", "IN"); + return true; + } + return false; +} + + /* The parser generates generic data structures, we need to set them up as the rest of the code expects to find them. This is in reality part @@ -2221,6 +2239,8 @@ int partition_info::fix_parser_data(THD *thd) part_elem= it++; List_iterator<part_elem_value> list_val_it(part_elem->list_val_list); num_elements= part_elem->list_val_list.elements; + if (!num_elements && error_if_requires_values()) + DBUG_RETURN(true); DBUG_ASSERT(part_type == RANGE_PARTITION ? num_elements == 1U : TRUE); for (j= 0; j < num_elements; j++) diff --git a/sql/partition_info.h b/sql/partition_info.h index cff941a858a..779948eddc9 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -313,6 +313,7 @@ public: void set_show_version_string(String *packet); void report_part_expr_error(bool use_subpart_expr); bool has_same_partitioning(partition_info *new_part_info); + bool error_if_requires_values() const; private: static int list_part_cmp(const void* a, const void* b); bool set_up_default_partitions(handler *file, HA_CREATE_INFO *info, diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index ab31a8c1791..01dcc7cc2ac 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4770,16 +4770,11 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, my_error(ER_PARTITION_WRONG_VALUES_ERROR, MYF(0), "LIST", "IN"); } - else if (tab_part_info->part_type == RANGE_PARTITION) - { - my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), - "RANGE", "LESS THAN"); - } else { - DBUG_ASSERT(tab_part_info->part_type == LIST_PARTITION); - my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), - "LIST", "IN"); + DBUG_ASSERT(tab_part_info->part_type == RANGE_PARTITION || + tab_part_info->part_type == LIST_PARTITION); + (void) tab_part_info->error_if_requires_values(); } goto err; } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 4805cd4c66a..e1c6b5b6276 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4679,18 +4679,8 @@ opt_part_values: partition_info *part_info= lex->part_info; if (! lex->is_partition_management()) { - if (part_info->part_type == RANGE_PARTITION) - { - my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), - "RANGE", "LESS THAN"); - MYSQL_YYABORT; - } - if (part_info->part_type == LIST_PARTITION) - { - my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0), - "LIST", "IN"); - MYSQL_YYABORT; - } + if (part_info->error_if_requires_values()) + MYSQL_YYABORT; } else part_info->part_type= HASH_PARTITION; |