Skip to content

Commit 8c9fd07

Browse files
committed
- Fix MDEV-9779. Avoid buffer overflow when setting partname.
modified: storage/connect/ha_connect.cc modified: storage/connect/ha_connect.h
1 parent 2c4715b commit 8c9fd07

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

storage/connect/ha_connect.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ ha_connect::ha_connect(handlerton *hton, TABLE_SHARE *table_arg)
757757
sdvalout= NULL;
758758
xmod= MODE_ANY;
759759
istable= false;
760-
*partname= 0;
760+
memset(partname, 0, sizeof(partname));
761761
bzero((char*) &xinfo, sizeof(XINFO));
762762
valid_info= false;
763763
valid_query_id= 0;
@@ -3123,13 +3123,14 @@ int ha_connect::open(const char *name, int mode, uint test_if_locked)
31233123
#if defined(WITH_PARTITION_STORAGE_ENGINE)
31243124
if (table->part_info) {
31253125
if (GetStringOption("Filename") || GetStringOption("Tabname")
3126-
|| GetStringOption("Connect")) {
3127-
strcpy(partname, decode(g, strrchr(name, '#') + 1));
3126+
|| GetStringOption("Connect")) {
3127+
strncpy(partname, decode(g, strrchr(name, '#') + 1), sizeof(partname) - 1);
31283128
// strcpy(partname, table->part_info->curr_part_elem->partition_name);
3129-
part_id= &table->part_info->full_part_field_set;
3129+
// part_id= &table->part_info->full_part_field_set;
31303130
} else // Inward table
3131-
strcpy(partname, strrchr(name, slash) + 1);
3132-
part_id= &table->part_info->full_part_field_set; // Temporary
3131+
strncpy(partname, strrchr(name, slash) + 1, sizeof(partname) - 1);
3132+
3133+
part_id= &table->part_info->full_part_field_set; // Temporary
31333134
} // endif part_info
31343135
#endif // WITH_PARTITION_STORAGE_ENGINE
31353136
} else
@@ -6144,7 +6145,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
61446145

61456146
strcpy(dbpath, name);
61466147
p= strrchr(dbpath, slash);
6147-
strcpy(partname, ++p);
6148+
strncpy(partname, ++p, sizeof(partname) - 1);
61486149
strcat(strcat(strcpy(buf, p), "."), lwt);
61496150
*p= 0;
61506151
} else {
@@ -6195,7 +6196,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
61956196

61966197
#if defined(WITH_PARTITION_STORAGE_ENGINE)
61976198
if (part_info && !inward)
6198-
strcpy(partname, decode(g, strrchr(name, '#') + 1));
6199+
strncpy(partname, decode(g, strrchr(name, '#') + 1), sizeof(partname) - 1);
61996200
// strcpy(partname, part_info->curr_part_elem->partition_name);
62006201
#endif // WITH_PARTITION_STORAGE_ENGINE
62016202

@@ -6236,8 +6237,9 @@ int ha_connect::create(const char *name, TABLE *table_arg,
62366237

62376238
#if defined(WITH_PARTITION_STORAGE_ENGINE)
62386239
if (part_info)
6239-
strcpy(partname,
6240-
decode(g, strrchr(name, (inward ? slash : '#')) + 1));
6240+
strncpy(partname,
6241+
decode(g, strrchr(name, (inward ? slash : '#')) + 1),
6242+
sizeof(partname) - 1);
62416243
#endif // WITH_PARTITION_STORAGE_ENGINE
62426244

62436245
if ((rc= optimize(table->in_use, NULL))) {

storage/connect/ha_connect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ int index_prev(uchar *buf);
554554
PVAL sdvalin4; // Used to convert date values
555555
PVAL sdvalout; // Used to convert date values
556556
bool istable; // True for table handler
557-
char partname[128]; // The partition name
557+
char partname[65]; // The partition name
558558
MODE xmod; // Table mode
559559
XINFO xinfo; // The table info structure
560560
bool valid_info; // True if xinfo is valid

0 commit comments

Comments
 (0)