Commit 360e597c authored by Jan Lindström's avatar Jan Lindström

Make sure name buffer has string end marker on correct place.

parent 1ad294e0
......@@ -1433,10 +1433,12 @@ dict_foreign_def_get(
const char* tbname;
char tablebuf[MAX_TABLE_NAME_LEN + 1] = "";
int i;
char* bufend;
tbname = dict_remove_db_name(foreign->id);
innobase_convert_name(tablebuf, MAX_TABLE_NAME_LEN,
bufend = innobase_convert_name(tablebuf, MAX_TABLE_NAME_LEN,
tbname, strlen(tbname), trx->mysql_thd, FALSE);
tablebuf[bufend - tablebuf] = '\0';
sprintf(fk_def,
(char *)"CONSTRAINT %s FOREIGN KEY (", (char *)tablebuf);
......@@ -1455,20 +1457,22 @@ dict_foreign_def_get(
strcat(fk_def,(char *)") REFERENCES ");
innobase_convert_name(tablebuf, MAX_TABLE_NAME_LEN,
foreign->referenced_table_name,
strlen(foreign->referenced_table_name),
trx->mysql_thd, TRUE);
bufend = innobase_convert_name(tablebuf, MAX_TABLE_NAME_LEN,
foreign->referenced_table_name,
strlen(foreign->referenced_table_name),
trx->mysql_thd, TRUE);
tablebuf[bufend - tablebuf] = '\0';
strcat(fk_def, tablebuf);
strcat(fk_def, " (");
for(i = 0; i < foreign->n_fields; i++) {
char buf[MAX_TABLE_NAME_LEN + 1] = "";
innobase_convert_name(buf, MAX_TABLE_NAME_LEN,
bufend = innobase_convert_name(buf, MAX_TABLE_NAME_LEN,
foreign->referenced_col_names[i],
strlen(foreign->referenced_col_names[i]),
trx->mysql_thd, FALSE);
buf[bufend - buf] = '\0';
strcat(fk_def, buf);
if (i < foreign->n_fields-1) {
strcat(fk_def, (char *)",");
......@@ -1492,18 +1496,25 @@ dict_foreign_def_get_fields(
char** field2, /*!< out: referenced column */
int col_no) /*!< in: column number */
{
*field = mem_heap_alloc(foreign->heap, MAX_TABLE_NAME_LEN+1);
*field2 = mem_heap_alloc(foreign->heap, MAX_TABLE_NAME_LEN+1);
innobase_convert_name(*field, MAX_TABLE_NAME_LEN,
foreign->foreign_col_names[col_no],
strlen(foreign->foreign_col_names[col_no]),
trx->mysql_thd, FALSE);
innobase_convert_name(*field, MAX_TABLE_NAME_LEN,
foreign->referenced_col_names[col_no],
strlen(foreign->referenced_col_names[col_no]),
trx->mysql_thd, FALSE);
char* bufend;
char* fieldbuf = mem_heap_alloc(foreign->heap, MAX_TABLE_NAME_LEN+1);
char* fieldbuf2 = mem_heap_alloc(foreign->heap, MAX_TABLE_NAME_LEN+1);
bufend = innobase_convert_name(fieldbuf, MAX_TABLE_NAME_LEN,
foreign->foreign_col_names[col_no],
strlen(foreign->foreign_col_names[col_no]),
trx->mysql_thd, FALSE);
fieldbuf[bufend - fieldbuf] = '\0';
bufend = innobase_convert_name(fieldbuf2, MAX_TABLE_NAME_LEN,
foreign->referenced_col_names[col_no],
strlen(foreign->referenced_col_names[col_no]),
trx->mysql_thd, FALSE);
fieldbuf2[bufend - fieldbuf2] = '\0';
*field = fieldbuf;
*field2 = fieldbuf2;
}
/********************************************************************//**
......
......@@ -3746,7 +3746,7 @@ dict_create_foreign_constraints_low(
const char* referenced_table_name;
const char* create_table_name;
const char* orig;
const char create_name[MAX_TABLE_NAME_LEN + 1];
char create_name[MAX_TABLE_NAME_LEN + 1];
const char operation[8];
ut_ad(mutex_own(&(dict_sys->mutex)));
......@@ -3770,14 +3770,18 @@ dict_create_foreign_constraints_low(
}
if (success) {
innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
create_table_name, strlen(create_table_name),
trx->mysql_thd, TRUE);
char *bufend;
bufend = innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
create_table_name, strlen(create_table_name),
trx->mysql_thd, TRUE);
create_name[bufend-create_name]='\0';
ptr = orig;
} else {
char *bufend;
ptr = orig;
innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
name, strlen(name), trx->mysql_thd, TRUE);
bufend = innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
name, strlen(name), trx->mysql_thd, TRUE);
create_name[bufend-create_name]='\0';
}
goto loop;
......@@ -3819,13 +3823,18 @@ dict_create_foreign_constraints_low(
&success, heap, &referenced_table_name);
if (table_to_alter) {
innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
table_to_alter->name, strlen(table_to_alter->name),
trx->mysql_thd, TRUE);
char *bufend;
bufend = innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
table_to_alter->name, strlen(table_to_alter->name),
trx->mysql_thd, TRUE);
create_name[bufend-create_name]='\0';
} else {
innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
referenced_table_name, strlen(referenced_table_name),
trx->mysql_thd, TRUE);
char *bufend;
bufend = innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
referenced_table_name, strlen(referenced_table_name),
trx->mysql_thd, TRUE);
create_name[bufend-create_name]='\0';
}
if (!success) {
......@@ -4128,10 +4137,12 @@ col_loop1:
if (!success || (!referenced_table && trx->check_foreigns)) {
char buf[MAX_TABLE_NAME_LEN + 1] = "";
char* bufend;
innobase_convert_name(buf, MAX_TABLE_NAME_LEN,
referenced_table_name, strlen(referenced_table_name),
trx->mysql_thd, TRUE);
bufend = innobase_convert_name(buf, MAX_TABLE_NAME_LEN,
referenced_table_name, strlen(referenced_table_name),
trx->mysql_thd, TRUE);
buf[bufend - buf] = '\0';
ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT,
"%s table %s with foreign key constraint failed. Referenced table %s not found in the data dictionary "
......
......@@ -1640,10 +1640,12 @@ dict_foreign_def_get(
const char* tbname;
char tablebuf[MAX_TABLE_NAME_LEN + 1] = "";
int i;
char* bufend;
tbname = dict_remove_db_name(foreign->id);
innobase_convert_name(tablebuf, MAX_TABLE_NAME_LEN,
bufend = innobase_convert_name(tablebuf, MAX_TABLE_NAME_LEN,
tbname, strlen(tbname), trx->mysql_thd, FALSE);
tablebuf[bufend - tablebuf] = '\0';
sprintf(fk_def,
(char *)"CONSTRAINT %s FOREIGN KEY (", (char *)tablebuf);
......@@ -1662,20 +1664,22 @@ dict_foreign_def_get(
strcat(fk_def,(char *)") REFERENCES ");
innobase_convert_name(tablebuf, MAX_TABLE_NAME_LEN,
foreign->referenced_table_name,
strlen(foreign->referenced_table_name),
trx->mysql_thd, TRUE);
bufend = innobase_convert_name(tablebuf, MAX_TABLE_NAME_LEN,
foreign->referenced_table_name,
strlen(foreign->referenced_table_name),
trx->mysql_thd, TRUE);
tablebuf[bufend - tablebuf] = '\0';
strcat(fk_def, tablebuf);
strcat(fk_def, " (");
for(i = 0; i < foreign->n_fields; i++) {
char buf[MAX_TABLE_NAME_LEN + 1] = "";
innobase_convert_name(buf, MAX_TABLE_NAME_LEN,
bufend = innobase_convert_name(buf, MAX_TABLE_NAME_LEN,
foreign->referenced_col_names[i],
strlen(foreign->referenced_col_names[i]),
trx->mysql_thd, FALSE);
buf[bufend - buf] = '\0';
strcat(fk_def, buf);
if (i < foreign->n_fields-1) {
strcat(fk_def, (char *)",");
......@@ -1699,18 +1703,25 @@ dict_foreign_def_get_fields(
char** field2, /*!< out: referenced column */
int col_no) /*!< in: column number */
{
*field = mem_heap_alloc(foreign->heap, MAX_TABLE_NAME_LEN+1);
*field2 = mem_heap_alloc(foreign->heap, MAX_TABLE_NAME_LEN+1);
innobase_convert_name(*field, MAX_TABLE_NAME_LEN,
foreign->foreign_col_names[col_no],
strlen(foreign->foreign_col_names[col_no]),
trx->mysql_thd, FALSE);
innobase_convert_name(*field, MAX_TABLE_NAME_LEN,
foreign->referenced_col_names[col_no],
strlen(foreign->referenced_col_names[col_no]),
trx->mysql_thd, FALSE);
char* bufend;
char* fieldbuf = mem_heap_alloc(foreign->heap, MAX_TABLE_NAME_LEN+1);
char* fieldbuf2 = mem_heap_alloc(foreign->heap, MAX_TABLE_NAME_LEN+1);
bufend = innobase_convert_name(fieldbuf, MAX_TABLE_NAME_LEN,
foreign->foreign_col_names[col_no],
strlen(foreign->foreign_col_names[col_no]),
trx->mysql_thd, FALSE);
fieldbuf[bufend - fieldbuf] = '\0';
bufend = innobase_convert_name(fieldbuf2, MAX_TABLE_NAME_LEN,
foreign->referenced_col_names[col_no],
strlen(foreign->referenced_col_names[col_no]),
trx->mysql_thd, FALSE);
fieldbuf2[bufend - fieldbuf2] = '\0';
*field = fieldbuf;
*field2 = fieldbuf2;
}
/********************************************************************//**
......
......@@ -3879,7 +3879,7 @@ dict_create_foreign_constraints_low(
const char* referenced_table_name;
const char* create_table_name;
const char* orig;
const char create_name[MAX_TABLE_NAME_LEN + 1];
char create_name[MAX_TABLE_NAME_LEN + 1];
const char operation[8];
ut_ad(mutex_own(&(dict_sys->mutex)));
......@@ -3903,14 +3903,18 @@ dict_create_foreign_constraints_low(
}
if (success) {
innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
create_table_name, strlen(create_table_name),
trx->mysql_thd, TRUE);
char *bufend;
bufend = innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
create_table_name, strlen(create_table_name),
trx->mysql_thd, TRUE);
create_name[bufend-create_name]='\0';
ptr = orig;
} else {
char *bufend;
ptr = orig;
innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
name, strlen(name), trx->mysql_thd, TRUE);
bufend = innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
name, strlen(name), trx->mysql_thd, TRUE);
create_name[bufend-create_name]='\0';
}
goto loop;
......@@ -3952,13 +3956,18 @@ dict_create_foreign_constraints_low(
&success, heap, &referenced_table_name);
if (table_to_alter) {
innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
table_to_alter->name, strlen(table_to_alter->name),
trx->mysql_thd, TRUE);
char *bufend;
bufend = innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
table_to_alter->name, strlen(table_to_alter->name),
trx->mysql_thd, TRUE);
create_name[bufend-create_name]='\0';
} else {
innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
referenced_table_name, strlen(referenced_table_name),
trx->mysql_thd, TRUE);
char *bufend;
bufend = innobase_convert_name((char *)create_name, MAX_TABLE_NAME_LEN,
referenced_table_name, strlen(referenced_table_name),
trx->mysql_thd, TRUE);
create_name[bufend-create_name]='\0';
}
if (!success) {
......@@ -4261,10 +4270,12 @@ col_loop1:
if (!success || (!referenced_table && trx->check_foreigns)) {
char buf[MAX_TABLE_NAME_LEN + 1] = "";
char* bufend;
innobase_convert_name(buf, MAX_TABLE_NAME_LEN,
referenced_table_name, strlen(referenced_table_name),
trx->mysql_thd, TRUE);
bufend = innobase_convert_name(buf, MAX_TABLE_NAME_LEN,
referenced_table_name, strlen(referenced_table_name),
trx->mysql_thd, TRUE);
buf[bufend - buf] = '\0';
ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT,
"%s table %s with foreign key constraint failed. Referenced table %s not found in the data dictionary "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment