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
@@ -193,7 +193,7 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g)
|
||||
*pcrp = crp->Next;
|
||||
} else if (!stricmp(Picol, crp->Name)) {
|
||||
if (crp->Nulls) {
|
||||
sprintf(g->Message, "Pivot column %s cannot be nullable", Picol);
|
||||
snprintf(g->Message, sizeof(g->Message), "Pivot column %s cannot be nullable", Picol);
|
||||
goto err;
|
||||
} // endif Nulls
|
||||
|
||||
@@ -550,14 +550,14 @@ bool TDBPIVOT::MakePivotColumns(PGLOBAL g)
|
||||
// Now it is time to allocate the pivot and function columns
|
||||
if (!(Fcolp = Tdbp->ColDB(g, Fncol, 0))) {
|
||||
// Function column not found in table
|
||||
sprintf(g->Message, MSG(COL_ISNOT_TABLE), Fncol, Tabname);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(COL_ISNOT_TABLE), Fncol, Tabname);
|
||||
return true;
|
||||
} else if (Fcolp->InitValue(g))
|
||||
return true;
|
||||
|
||||
if (!(Xcolp = Tdbp->ColDB(g, Picol, 0))) {
|
||||
// Pivot column not found in table
|
||||
sprintf(g->Message, MSG(COL_ISNOT_TABLE), Picol, Tabname);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(COL_ISNOT_TABLE), Picol, Tabname);
|
||||
return true;
|
||||
} else if (Xcolp->InitValue(g))
|
||||
return true;
|
||||
@@ -671,7 +671,7 @@ bool TDBPIVOT::OpenDB(PGLOBAL g)
|
||||
/*******************************************************************/
|
||||
/* Currently PIVOT tables cannot be modified. */
|
||||
/*******************************************************************/
|
||||
sprintf(g->Message, MSG(TABLE_READ_ONLY), "PIVOT");
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(TABLE_READ_ONLY), "PIVOT");
|
||||
return TRUE;
|
||||
} // endif Mode
|
||||
|
||||
@@ -797,7 +797,7 @@ int TDBPIVOT::ReadDB(PGLOBAL g)
|
||||
/***********************************************************************/
|
||||
int TDBPIVOT::WriteDB(PGLOBAL g)
|
||||
{
|
||||
sprintf(g->Message, MSG(TABLE_READ_ONLY), "PIVOT");
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(TABLE_READ_ONLY), "PIVOT");
|
||||
return RC_FX;
|
||||
} // end of WriteDB
|
||||
|
||||
@@ -806,7 +806,7 @@ int TDBPIVOT::WriteDB(PGLOBAL g)
|
||||
/***********************************************************************/
|
||||
int TDBPIVOT::DeleteDB(PGLOBAL g, int)
|
||||
{
|
||||
sprintf(g->Message, MSG(NO_TABLE_DEL), "PIVOT");
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(NO_TABLE_DEL), "PIVOT");
|
||||
return RC_FX;
|
||||
} // end of DeleteDB
|
||||
|
||||
|
Reference in New Issue
Block a user