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
@@ -152,14 +152,14 @@ PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info)
|
||||
#if defined(CMGO_SUPPORT)
|
||||
cmgd = new(g) CMGDISC(g, (int*)length);
|
||||
#else
|
||||
sprintf(g->Message, "Mongo %s Driver not available", "C");
|
||||
snprintf(g->Message, sizeof(g->Message), "Mongo %s Driver not available", "C");
|
||||
goto err;
|
||||
#endif
|
||||
} else if (drv && toupper(*drv) == 'J') {
|
||||
#if defined(JAVA_SUPPORT)
|
||||
cmgd = new(g) JMGDISC(g, (int*)length);
|
||||
#else
|
||||
sprintf(g->Message, "Mongo %s Driver not available", "Java");
|
||||
snprintf(g->Message, sizeof(g->Message), "Mongo %s Driver not available", "Java");
|
||||
goto err;
|
||||
#endif
|
||||
} else { // Driver not specified
|
||||
@@ -421,7 +421,7 @@ PTDB MGODEF::GetTable(PGLOBAL g, MODE m)
|
||||
else
|
||||
return new(g) TDBCMG(this);
|
||||
#else
|
||||
sprintf(g->Message, "Mongo %s Driver not available", "C");
|
||||
snprintf(g->Message, sizeof(g->Message), "Mongo %s Driver not available", "C");
|
||||
return NULL;
|
||||
#endif
|
||||
} else if (Driver && toupper(*Driver) == 'J') {
|
||||
@@ -431,7 +431,7 @@ PTDB MGODEF::GetTable(PGLOBAL g, MODE m)
|
||||
else
|
||||
return new(g) TDBJMG(this);
|
||||
#else
|
||||
sprintf(g->Message, "Mongo %s Driver not available", "Java");
|
||||
snprintf(g->Message, sizeof(g->Message), "Mongo %s Driver not available", "Java");
|
||||
return NULL;
|
||||
#endif
|
||||
} else { // Driver not specified
|
||||
|
Reference in New Issue
Block a user