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
@@ -85,7 +85,7 @@ bool TDBZIP::open(PGLOBAL g, const char *fn)
|
||||
PlugSetPath(filename, fn, GetPath());
|
||||
|
||||
if (!zipfile && !(zipfile = unzOpen64(filename)))
|
||||
sprintf(g->Message, "Zipfile open error");
|
||||
snprintf(g->Message, sizeof(g->Message), "Zipfile open error");
|
||||
|
||||
return (zipfile == NULL);
|
||||
} // end of open
|
||||
@@ -155,7 +155,7 @@ int TDBZIP::ReadDB(PGLOBAL g)
|
||||
if (nexterr == UNZ_END_OF_LIST_OF_FILE)
|
||||
return RC_EF;
|
||||
else if (nexterr != UNZ_OK) {
|
||||
sprintf(g->Message, "unzGoToNextFile error %d", nexterr);
|
||||
snprintf(g->Message, sizeof(g->Message), "unzGoToNextFile error %d", nexterr);
|
||||
return RC_FX;
|
||||
} // endif nexterr
|
||||
|
||||
@@ -163,7 +163,7 @@ int TDBZIP::ReadDB(PGLOBAL g)
|
||||
sizeof(fn), NULL, 0, NULL, 0);
|
||||
|
||||
if (err != UNZ_OK) {
|
||||
sprintf(g->Message, "unzGetCurrentFileInfo64 error %d", err);
|
||||
snprintf(g->Message, sizeof(g->Message), "unzGetCurrentFileInfo64 error %d", err);
|
||||
return RC_FX;
|
||||
} // endif err
|
||||
|
||||
|
Reference in New Issue
Block a user