Skip to content

Commit

Permalink
- Fix MDEV-9779. Avoid buffer overflow when setting partname.
Browse files Browse the repository at this point in the history
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/ha_connect.h
  • Loading branch information
Buggynours committed Mar 25, 2016
1 parent 2c4715b commit 8c9fd07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions storage/connect/ha_connect.cc
Expand Up @@ -757,7 +757,7 @@ ha_connect::ha_connect(handlerton *hton, TABLE_SHARE *table_arg)
sdvalout= NULL;
xmod= MODE_ANY;
istable= false;
*partname= 0;
memset(partname, 0, sizeof(partname));
bzero((char*) &xinfo, sizeof(XINFO));
valid_info= false;
valid_query_id= 0;
Expand Down Expand Up @@ -3123,13 +3123,14 @@ int ha_connect::open(const char *name, int mode, uint test_if_locked)
#if defined(WITH_PARTITION_STORAGE_ENGINE)
if (table->part_info) {
if (GetStringOption("Filename") || GetStringOption("Tabname")
|| GetStringOption("Connect")) {
strcpy(partname, decode(g, strrchr(name, '#') + 1));
|| GetStringOption("Connect")) {
strncpy(partname, decode(g, strrchr(name, '#') + 1), sizeof(partname) - 1);
// strcpy(partname, table->part_info->curr_part_elem->partition_name);
part_id= &table->part_info->full_part_field_set;
// part_id= &table->part_info->full_part_field_set;
} else // Inward table
strcpy(partname, strrchr(name, slash) + 1);
part_id= &table->part_info->full_part_field_set; // Temporary
strncpy(partname, strrchr(name, slash) + 1, sizeof(partname) - 1);

part_id= &table->part_info->full_part_field_set; // Temporary
} // endif part_info
#endif // WITH_PARTITION_STORAGE_ENGINE
} else
Expand Down Expand Up @@ -6144,7 +6145,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,

strcpy(dbpath, name);
p= strrchr(dbpath, slash);
strcpy(partname, ++p);
strncpy(partname, ++p, sizeof(partname) - 1);
strcat(strcat(strcpy(buf, p), "."), lwt);
*p= 0;
} else {
Expand Down Expand Up @@ -6195,7 +6196,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,

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

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

#if defined(WITH_PARTITION_STORAGE_ENGINE)
if (part_info)
strcpy(partname,
decode(g, strrchr(name, (inward ? slash : '#')) + 1));
strncpy(partname,
decode(g, strrchr(name, (inward ? slash : '#')) + 1),
sizeof(partname) - 1);
#endif // WITH_PARTITION_STORAGE_ENGINE

if ((rc= optimize(table->in_use, NULL))) {
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/ha_connect.h
Expand Up @@ -554,7 +554,7 @@ int index_prev(uchar *buf);
PVAL sdvalin4; // Used to convert date values
PVAL sdvalout; // Used to convert date values
bool istable; // True for table handler
char partname[128]; // The partition name
char partname[65]; // The partition name
MODE xmod; // Table mode
XINFO xinfo; // The table info structure
bool valid_info; // True if xinfo is valid
Expand Down

0 comments on commit 8c9fd07

Please sign in to comment.