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
@@ -318,7 +318,7 @@ int TDBINI::DeleteDB(PGLOBAL g, int irc)
|
||||
case RC_FX:
|
||||
while (ReadDB(g) == RC_OK)
|
||||
if (!WritePrivateProfileString(Section, NULL, NULL, Ifile)) {
|
||||
sprintf(g->Message, "Error %d accessing %s",
|
||||
snprintf(g->Message, sizeof(g->Message), "Error %d accessing %s",
|
||||
GetLastError(), Ifile);
|
||||
return RC_FX;
|
||||
} // endif
|
||||
@@ -330,7 +330,7 @@ int TDBINI::DeleteDB(PGLOBAL g, int irc)
|
||||
return RC_FX;
|
||||
} else
|
||||
if (!WritePrivateProfileString(Section, NULL, NULL, Ifile)) {
|
||||
sprintf(g->Message, "Error %d accessing %s",
|
||||
snprintf(g->Message, sizeof(g->Message), "Error %d accessing %s",
|
||||
GetLastError(), Ifile);
|
||||
return RC_FX;
|
||||
} // endif rc
|
||||
@@ -401,7 +401,7 @@ void INICOL::AllocBuf(PGLOBAL g)
|
||||
bool INICOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check)
|
||||
{
|
||||
if (!(To_Val = value)) {
|
||||
sprintf(g->Message, MSG(VALUE_ERROR), Name);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(VALUE_ERROR), Name);
|
||||
return true;
|
||||
} else if (Buf_Type == value->GetType()) {
|
||||
// Values are of the (good) column type
|
||||
@@ -420,7 +420,7 @@ bool INICOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check)
|
||||
} else {
|
||||
// Values are not of the (good) column type
|
||||
if (check) {
|
||||
sprintf(g->Message, MSG(TYPE_VALUE_ERR), Name,
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(TYPE_VALUE_ERR), Name,
|
||||
GetTypeName(Buf_Type), GetTypeName(value->GetType()));
|
||||
return true;
|
||||
} // endif check
|
||||
@@ -510,7 +510,7 @@ void INICOL::WriteColumn(PGLOBAL g)
|
||||
p = Value->GetCharString(Valbuf);
|
||||
|
||||
if (strlen(p) > (unsigned)Long) {
|
||||
sprintf(g->Message, MSG(VALUE_TOO_LONG), p, Name, Long);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(VALUE_TOO_LONG), p, Name, Long);
|
||||
throw 31;
|
||||
} else if (Flag == 1) {
|
||||
if (tdbp->Mode == MODE_UPDATE) {
|
||||
@@ -534,7 +534,7 @@ void INICOL::WriteColumn(PGLOBAL g)
|
||||
rc = WritePrivateProfileString(tdbp->Section, Name, p, tdbp->Ifile);
|
||||
|
||||
if (!rc) {
|
||||
sprintf(g->Message, "Error %d writing to %s",
|
||||
snprintf(g->Message, sizeof(g->Message), "Error %d writing to %s",
|
||||
GetLastError(), tdbp->Ifile);
|
||||
throw 31;
|
||||
} // endif rc
|
||||
@@ -746,7 +746,7 @@ int TDBXIN::DeleteDB(PGLOBAL g, int irc)
|
||||
} else if (irc == RC_FX) {
|
||||
for (Section = Seclist; *Section; Section += (strlen(Section) + 1))
|
||||
if (!WritePrivateProfileString(Section, NULL, NULL, Ifile)) {
|
||||
sprintf(g->Message, "Error %d accessing %s",
|
||||
snprintf(g->Message, sizeof(g->Message), "Error %d accessing %s",
|
||||
GetLastError(), Ifile);
|
||||
return RC_FX;
|
||||
} // endif
|
||||
@@ -756,7 +756,7 @@ int TDBXIN::DeleteDB(PGLOBAL g, int irc)
|
||||
return RC_FX;
|
||||
} else
|
||||
if (!WritePrivateProfileString(Section, Keycur, NULL, Ifile)) {
|
||||
sprintf(g->Message, "Error %d accessing %s",
|
||||
snprintf(g->Message, sizeof(g->Message), "Error %d accessing %s",
|
||||
GetLastError(), Ifile);
|
||||
return RC_FX;
|
||||
} // endif
|
||||
@@ -836,7 +836,7 @@ void XINCOL::WriteColumn(PGLOBAL g)
|
||||
p = Value->GetCharString(Valbuf);
|
||||
|
||||
if (strlen(p) > (unsigned)Long) {
|
||||
sprintf(g->Message, MSG(VALUE_TOO_LONG), p, Name, Long);
|
||||
snprintf(g->Message, sizeof(g->Message), MSG(VALUE_TOO_LONG), p, Name, Long);
|
||||
throw 31;
|
||||
} else if (Flag == 1) {
|
||||
if (tdbp->Mode == MODE_UPDATE) {
|
||||
@@ -870,7 +870,7 @@ void XINCOL::WriteColumn(PGLOBAL g)
|
||||
rc = WritePrivateProfileString(tdbp->Section, tdbp->Keycur, p, tdbp->Ifile);
|
||||
|
||||
if (!rc) {
|
||||
sprintf(g->Message, "Error %d writing to %s",
|
||||
snprintf(g->Message, sizeof(g->Message), "Error %d writing to %s",
|
||||
GetLastError(), tdbp->Ifile);
|
||||
throw 31;
|
||||
} // endif rc
|
||||
|
Reference in New Issue
Block a user