mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Use memory safe snprintf() in Connect Engine
This commit replaces sprintf(buf, ...) with snprintf(buf, sizeof(buf), ...), specifically in the "easy" cases where buf is allocated with a size known at compile time. The changes make sure we are not write outside array/string bounds which will lead to undefined behaviour. In case the code is trying to write outside bounds - safe version of functions simply cut the string messages so we process this gracefully. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. bsonudf.cpp warnings cleanup by Daniel Black Reviewer: Daniel Black
This commit is contained in:
committed by
Daniel Black
parent
95eb5e5a12
commit
19af1890b5
@@ -109,7 +109,7 @@ TABLE_SHARE *GetTableShare(PGLOBAL g, THD *thd, const char *db,
|
||||
if (thd->is_error())
|
||||
thd->clear_error(); // Avoid stopping info commands
|
||||
|
||||
sprintf(g->Message, "Error %d opening share\n", s->error);
|
||||
snprintf(g->Message, sizeof(g->Message), "Error %d opening share\n", s->error);
|
||||
free_table_share(s);
|
||||
return NULL;
|
||||
} // endif open_table_def
|
||||
@@ -204,19 +204,19 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
|
||||
if ((type = MYSQLtoPLG(fp->type(), &v)) == TYPE_ERROR) {
|
||||
if (v == 'K') {
|
||||
// Skip this column
|
||||
sprintf(g->Message, "Column %s skipped (unsupported type)", colname);
|
||||
snprintf(g->Message, sizeof(g->Message), "Column %s skipped (unsupported type)", colname);
|
||||
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
|
||||
continue;
|
||||
} // endif v
|
||||
|
||||
sprintf(g->Message, "Column %s unsupported type", colname);
|
||||
snprintf(g->Message, sizeof(g->Message), "Column %s unsupported type", colname);
|
||||
qrp = NULL;
|
||||
break;
|
||||
} // endif type
|
||||
|
||||
if (v == 'X') {
|
||||
len = zconv;
|
||||
sprintf(g->Message, "Column %s converted to varchar(%d)",
|
||||
snprintf(g->Message, sizeof(g->Message), "Column %s converted to varchar(%d)",
|
||||
colname, len);
|
||||
push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
|
||||
} // endif v
|
||||
@@ -411,7 +411,7 @@ PTDB TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
|
||||
cdb = (tp->Schema) ? tp->Schema : curdb;
|
||||
|
||||
if (!stricmp(name, tp->Name) && !stricmp(db, cdb)) {
|
||||
sprintf(g->Message, "Table %s.%s pointing on itself", db, name);
|
||||
snprintf(g->Message, sizeof(g->Message), "Table %s.%s pointing on itself", db, name);
|
||||
return NULL;
|
||||
} // endif
|
||||
|
||||
@@ -441,7 +441,7 @@ PTDB TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
|
||||
char buf[MAX_STR];
|
||||
|
||||
strcpy(buf, g->Message);
|
||||
snprintf(g->Message, MAX_STR, "Error accessing %s.%s: %s", db, name, buf);
|
||||
snprintf(g->Message, sizeof(g->Message), "Error accessing %s.%s: %s", db, name, buf);
|
||||
hc->tshp = NULL;
|
||||
goto err;
|
||||
} // endif Define
|
||||
@@ -578,7 +578,7 @@ bool TDBPRX::OpenDB(PGLOBAL g)
|
||||
PTDB utp;
|
||||
|
||||
if (!(utp= Tdbp->Duplicate(g))) {
|
||||
sprintf(g->Message, MSG(INV_UPDT_TABLE), Tdbp->GetName());
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(INV_UPDT_TABLE), Tdbp->GetName());
|
||||
return true;
|
||||
} // endif tp
|
||||
|
||||
@@ -721,7 +721,7 @@ bool PRXCOL::Init(PGLOBAL g, PTDB tp)
|
||||
// this may be needed by some tables (which?)
|
||||
Colp->SetColUse(ColUse);
|
||||
} else {
|
||||
sprintf(g->Message, MSG(NO_MATCHING_COL), Name, tp->GetName());
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(NO_MATCHING_COL), Name, tp->GetName());
|
||||
return true;
|
||||
} // endif Colp
|
||||
|
||||
|
Reference in New Issue
Block a user