Skip to content

Commit be901b6

Browse files
author
Nisha Gopalakrishnan
committed
Bug#26390632: CREATE TABLE CAN CAUSE MYSQL TO EXIT.
Analysis ======== CREATE TABLE of InnoDB table with a partition name which exceeds the path limit can cause the server to exit. During the preparation of the partition name, there was no check to identify whether the complete path name for partition exceeds the max supported path length, causing the server to exit during subsequent processing. Fix === During the preparation of partition name, check and report an error if the partition path name exceeds the maximum path name limit. This is a 5.5 patch.
1 parent ebd96c3 commit be901b6

File tree

3 files changed

+204
-129
lines changed

3 files changed

+204
-129
lines changed

sql/ha_partition.cc

Lines changed: 91 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -624,7 +624,7 @@ int ha_partition::create(const char *name, TABLE *table_arg,
624624
int ha_partition::drop_partitions(const char *path)
625625
{
626626
List_iterator<partition_element> part_it(m_part_info->partitions);
627-
char part_name_buff[FN_REFLEN];
627+
char part_name_buff[FN_REFLEN + 1];
628628
uint num_parts= m_part_info->partitions.elements;
629629
uint num_subparts= m_part_info->num_subparts;
630630
uint i= 0;
@@ -657,9 +657,12 @@ int ha_partition::drop_partitions(const char *path)
657657
{
658658
partition_element *sub_elem= sub_it++;
659659
part= i * num_subparts + j;
660-
create_subpartition_name(part_name_buff, path,
661-
part_elem->partition_name,
662-
sub_elem->partition_name, name_variant);
660+
if ((ret_error= create_subpartition_name(part_name_buff, path,
661+
part_elem->partition_name,
662+
sub_elem->partition_name,
663+
name_variant)))
664+
error= ret_error;
665+
663666
file= m_file[part];
664667
DBUG_PRINT("info", ("Drop subpartition %s", part_name_buff));
665668
if ((ret_error= file->ha_delete_table(part_name_buff)))
@@ -670,9 +673,11 @@ int ha_partition::drop_partitions(const char *path)
670673
}
671674
else
672675
{
673-
create_partition_name(part_name_buff, path,
674-
part_elem->partition_name, name_variant,
675-
TRUE);
676+
if ((ret_error= create_partition_name(part_name_buff, path,
677+
part_elem->partition_name,
678+
name_variant, TRUE)))
679+
error= ret_error;
680+
676681
file= m_file[i];
677682
DBUG_PRINT("info", ("Drop partition %s", part_name_buff));
678683
if ((ret_error= file->ha_delete_table(part_name_buff)))
@@ -714,8 +719,8 @@ int ha_partition::rename_partitions(const char *path)
714719
{
715720
List_iterator<partition_element> part_it(m_part_info->partitions);
716721
List_iterator<partition_element> temp_it(m_part_info->temp_partitions);
717-
char part_name_buff[FN_REFLEN];
718-
char norm_name_buff[FN_REFLEN];
722+
char part_name_buff[FN_REFLEN + 1];
723+
char norm_name_buff[FN_REFLEN + 1];
719724
uint num_parts= m_part_info->partitions.elements;
720725
uint part_count= 0;
721726
uint num_subparts= m_part_info->num_subparts;
@@ -757,10 +762,11 @@ int ha_partition::rename_partitions(const char *path)
757762
{
758763
sub_elem= sub_it++;
759764
file= m_reorged_file[part_count++];
760-
create_subpartition_name(norm_name_buff, path,
761-
part_elem->partition_name,
762-
sub_elem->partition_name,
763-
NORMAL_PART_NAME);
765+
if ((ret_error= create_subpartition_name(norm_name_buff, path,
766+
part_elem->partition_name,
767+
sub_elem->partition_name,
768+
NORMAL_PART_NAME)))
769+
error= ret_error;
764770
DBUG_PRINT("info", ("Delete subpartition %s", norm_name_buff));
765771
if ((ret_error= file->ha_delete_table(norm_name_buff)))
766772
error= ret_error;
@@ -773,9 +779,11 @@ int ha_partition::rename_partitions(const char *path)
773779
else
774780
{
775781
file= m_reorged_file[part_count++];
776-
create_partition_name(norm_name_buff, path,
777-
part_elem->partition_name, NORMAL_PART_NAME,
778-
TRUE);
782+
if ((ret_error= create_partition_name(norm_name_buff, path,
783+
part_elem->partition_name,
784+
NORMAL_PART_NAME, TRUE)))
785+
error= ret_error;
786+
779787
DBUG_PRINT("info", ("Delete partition %s", norm_name_buff));
780788
if ((ret_error= file->ha_delete_table(norm_name_buff)))
781789
error= ret_error;
@@ -825,10 +833,12 @@ int ha_partition::rename_partitions(const char *path)
825833
{
826834
sub_elem= sub_it++;
827835
part= i * num_subparts + j;
828-
create_subpartition_name(norm_name_buff, path,
829-
part_elem->partition_name,
830-
sub_elem->partition_name,
831-
NORMAL_PART_NAME);
836+
if ((ret_error= create_subpartition_name(norm_name_buff, path,
837+
part_elem->partition_name,
838+
sub_elem->partition_name,
839+
NORMAL_PART_NAME)))
840+
error= ret_error;
841+
832842
if (part_elem->part_state == PART_IS_CHANGED)
833843
{
834844
file= m_reorged_file[part_count++];
@@ -840,10 +850,12 @@ int ha_partition::rename_partitions(const char *path)
840850
(void) sync_ddl_log();
841851
}
842852
file= m_new_file[part];
843-
create_subpartition_name(part_name_buff, path,
844-
part_elem->partition_name,
845-
sub_elem->partition_name,
846-
TEMP_PART_NAME);
853+
if ((ret_error= create_subpartition_name(part_name_buff, path,
854+
part_elem->partition_name,
855+
sub_elem->partition_name,
856+
TEMP_PART_NAME)))
857+
error= ret_error;
858+
847859
DBUG_PRINT("info", ("Rename subpartition from %s to %s",
848860
part_name_buff, norm_name_buff));
849861
if ((ret_error= file->ha_rename_table(part_name_buff,
@@ -857,9 +869,11 @@ int ha_partition::rename_partitions(const char *path)
857869
}
858870
else
859871
{
860-
create_partition_name(norm_name_buff, path,
861-
part_elem->partition_name, NORMAL_PART_NAME,
862-
TRUE);
872+
if ((ret_error= create_partition_name(norm_name_buff, path,
873+
part_elem->partition_name,
874+
NORMAL_PART_NAME, TRUE)))
875+
error= ret_error;
876+
863877
if (part_elem->part_state == PART_IS_CHANGED)
864878
{
865879
file= m_reorged_file[part_count++];
@@ -871,9 +885,11 @@ int ha_partition::rename_partitions(const char *path)
871885
(void) sync_ddl_log();
872886
}
873887
file= m_new_file[i];
874-
create_partition_name(part_name_buff, path,
875-
part_elem->partition_name, TEMP_PART_NAME,
876-
TRUE);
888+
if ((ret_error= create_partition_name(part_name_buff, path,
889+
part_elem->partition_name,
890+
TEMP_PART_NAME, TRUE)))
891+
error= ret_error;
892+
877893
DBUG_PRINT("info", ("Rename partition from %s to %s",
878894
part_name_buff, norm_name_buff));
879895
if ((ret_error= file->ha_rename_table(part_name_buff,
@@ -1477,7 +1493,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
14771493
{
14781494
List_iterator<partition_element> part_it(m_part_info->partitions);
14791495
List_iterator <partition_element> t_it(m_part_info->temp_partitions);
1480-
char part_name_buff[FN_REFLEN];
1496+
char part_name_buff[FN_REFLEN + 1];
14811497
uint num_parts= m_part_info->partitions.elements;
14821498
uint num_subparts= m_part_info->num_subparts;
14831499
uint i= 0;
@@ -1687,10 +1703,15 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
16871703
do
16881704
{
16891705
partition_element *sub_elem= sub_it++;
1690-
create_subpartition_name(part_name_buff, path,
1691-
part_elem->partition_name,
1692-
sub_elem->partition_name,
1693-
name_variant);
1706+
if ((error= create_subpartition_name(part_name_buff, path,
1707+
part_elem->partition_name,
1708+
sub_elem->partition_name,
1709+
name_variant)))
1710+
{
1711+
cleanup_new_partition(part_count);
1712+
DBUG_RETURN(error);
1713+
}
1714+
16941715
part= i * num_subparts + j;
16951716
DBUG_PRINT("info", ("Add subpartition %s", part_name_buff));
16961717
if ((error= prepare_new_partition(table, create_info,
@@ -1708,9 +1729,14 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
17081729
}
17091730
else
17101731
{
1711-
create_partition_name(part_name_buff, path,
1712-
part_elem->partition_name, name_variant,
1713-
TRUE);
1732+
if ((error= create_partition_name(part_name_buff, path,
1733+
part_elem->partition_name,
1734+
name_variant, TRUE)))
1735+
{
1736+
cleanup_new_partition(part_count);
1737+
DBUG_RETURN(error);
1738+
}
1739+
17141740
DBUG_PRINT("info", ("Add partition %s", part_name_buff));
17151741
if ((error= prepare_new_partition(table, create_info,
17161742
new_file_array[i],
@@ -1967,8 +1993,8 @@ int ha_partition::del_ren_cre_table(const char *from,
19671993
{
19681994
int save_error= 0;
19691995
int error= HA_ERR_INTERNAL_ERROR;
1970-
char from_buff[FN_REFLEN], to_buff[FN_REFLEN], from_lc_buff[FN_REFLEN],
1971-
to_lc_buff[FN_REFLEN], buff[FN_REFLEN];
1996+
char from_buff[FN_REFLEN + 1], to_buff[FN_REFLEN + 1], from_lc_buff[FN_REFLEN + 1],
1997+
to_lc_buff[FN_REFLEN + 1], buff[FN_REFLEN + 1];
19721998
char *name_buffer_ptr;
19731999
const char *from_path;
19742000
const char *to_path= NULL;
@@ -2015,13 +2041,16 @@ int ha_partition::del_ren_cre_table(const char *from,
20152041
i= 0;
20162042
do
20172043
{
2018-
create_partition_name(from_buff, from_path, name_buffer_ptr,
2019-
NORMAL_PART_NAME, FALSE);
2044+
if ((error= create_partition_name(from_buff, from_path, name_buffer_ptr,
2045+
NORMAL_PART_NAME, FALSE)))
2046+
DBUG_RETURN(error);
20202047

20212048
if (to != NULL)
20222049
{ // Rename branch
2023-
create_partition_name(to_buff, to_path, name_buffer_ptr,
2024-
NORMAL_PART_NAME, FALSE);
2050+
if ((error= create_partition_name(to_buff, to_path, name_buffer_ptr,
2051+
NORMAL_PART_NAME, FALSE)))
2052+
DBUG_RETURN(error);
2053+
20252054
error= (*file)->ha_rename_table(from_buff, to_buff);
20262055
if (error)
20272056
goto rename_error;
@@ -2066,9 +2095,9 @@ int ha_partition::del_ren_cre_table(const char *from,
20662095
name_buffer_ptr= m_name_buffer_ptr;
20672096
for (abort_file= file, file= m_file; file < abort_file; file++)
20682097
{
2069-
create_partition_name(from_buff, from_path, name_buffer_ptr, NORMAL_PART_NAME,
2070-
FALSE);
2071-
(void) (*file)->ha_delete_table((const char*) from_buff);
2098+
if (!create_partition_name(from_buff, from_path, name_buffer_ptr, NORMAL_PART_NAME,
2099+
FALSE))
2100+
(void) (*file)->ha_delete_table((const char*) from_buff);
20722101
name_buffer_ptr= strend(name_buffer_ptr) + 1;
20732102
}
20742103
DBUG_RETURN(error);
@@ -2077,12 +2106,12 @@ int ha_partition::del_ren_cre_table(const char *from,
20772106
for (abort_file= file, file= m_file; file < abort_file; file++)
20782107
{
20792108
/* Revert the rename, back from 'to' to the original 'from' */
2080-
create_partition_name(from_buff, from_path, name_buffer_ptr,
2081-
NORMAL_PART_NAME, FALSE);
2082-
create_partition_name(to_buff, to_path, name_buffer_ptr,
2083-
NORMAL_PART_NAME, FALSE);
2084-
/* Ignore error here */
2085-
(void) (*file)->ha_rename_table(to_buff, from_buff);
2109+
if (!create_partition_name(from_buff, from_path, name_buffer_ptr,
2110+
NORMAL_PART_NAME, FALSE))
2111+
if (!create_partition_name(to_buff, to_path, name_buffer_ptr,
2112+
NORMAL_PART_NAME, FALSE))
2113+
/* Ignore error here */
2114+
(void) (*file)->ha_rename_table(to_buff, from_buff);
20862115
name_buffer_ptr= strend(name_buffer_ptr) + 1;
20872116
}
20882117
DBUG_RETURN(error);
@@ -2707,7 +2736,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
27072736
char *name_buffer_ptr;
27082737
int error= HA_ERR_INITIALIZATION;
27092738
handler **file;
2710-
char name_buff[FN_REFLEN];
2739+
char name_buff[FN_REFLEN + 1];
27112740
bool is_not_tmp_table= (table_share->tmp_table == NO_TMP_TABLE);
27122741
ulonglong check_table_flags;
27132742
DBUG_ENTER("ha_partition::open");
@@ -2777,8 +2806,10 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
27772806
file= m_is_clone_of->m_file;
27782807
for (i= 0; i < m_tot_parts; i++)
27792808
{
2780-
create_partition_name(name_buff, name, name_buffer_ptr, NORMAL_PART_NAME,
2781-
FALSE);
2809+
if ((error= create_partition_name(name_buff, name, name_buffer_ptr,
2810+
NORMAL_PART_NAME, FALSE)))
2811+
goto err_handler;
2812+
27822813
if (!(m_file[i]= file[i]->clone(name_buff, m_clone_mem_root)))
27832814
{
27842815
error= HA_ERR_INITIALIZATION;
@@ -2793,8 +2824,9 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
27932824
file= m_file;
27942825
do
27952826
{
2796-
create_partition_name(name_buff, name, name_buffer_ptr, NORMAL_PART_NAME,
2797-
FALSE);
2827+
if ((error= create_partition_name(name_buff, name, name_buffer_ptr,
2828+
NORMAL_PART_NAME, FALSE)))
2829+
goto err_handler;
27982830
if ((error= (*file)->ha_open(table, name_buff, mode, test_if_locked)))
27992831
goto err_handler;
28002832
m_num_locks+= (*file)->lock_count();

0 commit comments

Comments
 (0)