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
@@ -207,7 +207,7 @@ PCOL TDB::InsertSpcBlk(PGLOBAL g, PCOLDEF cdp)
|
||||
!stricmp(name, "FPATH") || !stricmp(name, "FNAME") ||
|
||||
!stricmp(name, "FTYPE") || !stricmp(name, "SERVID")) {
|
||||
if (!To_Def || !(To_Def->GetPseudo() & 2)) {
|
||||
sprintf(g->Message, MSG(BAD_SPEC_COLUMN));
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(BAD_SPEC_COLUMN));
|
||||
return NULL;
|
||||
} // endif Pseudo
|
||||
|
||||
@@ -235,12 +235,12 @@ PCOL TDB::InsertSpcBlk(PGLOBAL g, PCOLDEF cdp)
|
||||
} else if (!stricmp(name, "ROWNUM")) {
|
||||
colp = new(g)RIDBLK(cp, true);
|
||||
} else {
|
||||
sprintf(g->Message, MSG(BAD_SPECIAL_COL), name);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(BAD_SPECIAL_COL), name);
|
||||
return NULL;
|
||||
} // endif's name
|
||||
|
||||
if (!(colp = InsertSpecialColumn(colp))) {
|
||||
sprintf(g->Message, MSG(BAD_SPECIAL_COL), name);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(BAD_SPECIAL_COL), name);
|
||||
return NULL;
|
||||
} // endif Insert
|
||||
|
||||
@@ -266,7 +266,7 @@ void TDB::MarkDB(PGLOBAL, PTDB tdb2)
|
||||
/***********************************************************************/
|
||||
int TDB::RowNumber(PGLOBAL g, bool)
|
||||
{
|
||||
sprintf(g->Message, MSG(ROWID_NOT_IMPL), GetAmName(g, GetAmType()));
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(ROWID_NOT_IMPL), GetAmName(g, GetAmType()));
|
||||
return 0;
|
||||
} // end of RowNumber
|
||||
|
||||
@@ -495,7 +495,7 @@ PCOL TDBASE::InsertSpcBlk(PGLOBAL g, PCOLDEF cdp)
|
||||
!stricmp(name, "FPATH") || !stricmp(name, "FNAME") ||
|
||||
!stricmp(name, "FTYPE") || !stricmp(name, "SERVID")) {
|
||||
if (!To_Def || !(To_Def->GetPseudo() & 2)) {
|
||||
sprintf(g->Message, MSG(BAD_SPEC_COLUMN));
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(BAD_SPEC_COLUMN));
|
||||
return NULL;
|
||||
} // endif Pseudo
|
||||
|
||||
@@ -523,12 +523,12 @@ PCOL TDBASE::InsertSpcBlk(PGLOBAL g, PCOLDEF cdp)
|
||||
} else if (!stricmp(name, "ROWNUM")) {
|
||||
colp = new(g) RIDBLK(cp, true);
|
||||
} else {
|
||||
sprintf(g->Message, MSG(BAD_SPECIAL_COL), name);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(BAD_SPECIAL_COL), name);
|
||||
return NULL;
|
||||
} // endif's name
|
||||
|
||||
if (!(colp = InsertSpecialColumn(colp))) {
|
||||
sprintf(g->Message, MSG(BAD_SPECIAL_COL), name);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(BAD_SPECIAL_COL), name);
|
||||
return NULL;
|
||||
} // endif Insert
|
||||
|
||||
@@ -642,12 +642,12 @@ bool TDBCAT::Initialize(PGLOBAL g)
|
||||
return true;
|
||||
|
||||
if (Qrp->Truncated) {
|
||||
sprintf(g->Message, "Result limited to %d lines", Qrp->Maxres);
|
||||
snprintf(g->Message, sizeof(g->Message), "Result limited to %d lines", Qrp->Maxres);
|
||||
PushWarning(g, this);
|
||||
} // endif Truncated
|
||||
|
||||
if (Qrp->BadLines) {
|
||||
sprintf(g->Message, "%d bad lines in result", Qrp->BadLines);
|
||||
snprintf(g->Message, sizeof(g->Message), "%d bad lines in result", Qrp->BadLines);
|
||||
PushWarning(g, this);
|
||||
} // endif Badlines
|
||||
|
||||
@@ -720,7 +720,7 @@ bool TDBCAT::InitCol(PGLOBAL g)
|
||||
|
||||
|
||||
if (!colp->Crp /*&& !colp->GetValue()->IsConstant()*/) {
|
||||
sprintf(g->Message, "Invalid flag %d for column %s",
|
||||
snprintf(g->Message, sizeof(g->Message), "Invalid flag %d for column %s",
|
||||
colp->Flag, colp->Name);
|
||||
return true;
|
||||
} else if (crp->Fld == FLD_SCALE || crp->Fld == FLD_RADIX)
|
||||
|
Reference in New Issue
Block a user