summaryrefslogtreecommitdiff
path: root/storage/connect
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2022-10-02 22:14:21 +0200
committerSergei Golubchik <serg@mariadb.org>2022-10-02 22:14:21 +0200
commit900d7bf3604e7ba265f06d96f76a049dc3c4c9af (patch)
treec447b67842760bdc3ccae31aebb987fee4071842 /storage/connect
parent2ab52cc0e5c3cc792608a518625a08e6d3734ce4 (diff)
parent3a2116241b128b811ee2455845ff9710da3115ac (diff)
downloadmariadb-git-900d7bf3604e7ba265f06d96f76a049dc3c4c9af.tar.gz
Merge branch '10.5' into 10.6
Diffstat (limited to 'storage/connect')
-rw-r--r--storage/connect/bsonudf.cpp4
-rw-r--r--storage/connect/global.h2
-rw-r--r--storage/connect/ha_connect.cc18
-rw-r--r--storage/connect/ha_connect.h22
-rw-r--r--storage/connect/jdbconn.cpp10
-rw-r--r--storage/connect/json.cpp6
-rw-r--r--storage/connect/jsonudf.cpp4
-rw-r--r--storage/connect/libdoc.cpp38
-rw-r--r--storage/connect/mysql-test/connect/r/mysql.result22
-rw-r--r--storage/connect/mysql-test/connect/r/odbc_postgresql.result24
-rw-r--r--storage/connect/mysql-test/connect/t/mysql.test20
-rw-r--r--storage/connect/mysql-test/connect/t/odbc_postgresql.sql3
-rw-r--r--storage/connect/mysql-test/connect/t/odbc_postgresql.test6
-rw-r--r--storage/connect/plugutil.cpp17
-rw-r--r--storage/connect/tabbson.cpp4
-rw-r--r--storage/connect/tabodbc.cpp2
-rw-r--r--storage/connect/tabwmi.cpp2
-rw-r--r--storage/connect/valblk.cpp2
18 files changed, 136 insertions, 70 deletions
diff --git a/storage/connect/bsonudf.cpp b/storage/connect/bsonudf.cpp
index 1fc0b48c1f8..8dc892998cb 100644
--- a/storage/connect/bsonudf.cpp
+++ b/storage/connect/bsonudf.cpp
@@ -1146,7 +1146,7 @@ my_bool BJNX::LocateArray(PGLOBAL g, PBVAL jarp)
for (int i = 0; i < n && !Found; i++) {
Jp->N = m;
- sprintf(s, "[%d]", i + B);
+ snprintf(s, sizeof(s), "[%d]", i + B);
if (Jp->WriteStr(s))
return true;
@@ -1440,7 +1440,7 @@ my_bool BJNX::AddPath(void)
for (int i = 0; i <= I; i++) {
if (Jpnp[i].Type == TYPE_JAR) {
- sprintf(s, "[%d]", Jpnp[i].N + B);
+ snprintf(s, sizeof(s), "[%d]", Jpnp[i].N + B);
if (Jp->WriteStr(s))
return true;
diff --git a/storage/connect/global.h b/storage/connect/global.h
index eb3d4106477..bc1585eba41 100644
--- a/storage/connect/global.h
+++ b/storage/connect/global.h
@@ -14,6 +14,8 @@
#include <time.h> /* time_t type declaration */
#include <setjmp.h> /* Long jump declarations */
+#define ROUNDUP_TO_8(num) (((num + 7) / 8) * 8)
+
#if defined(_WIN32) && !defined(NOEX)
#define DllExport __declspec( dllexport )
#else // !_WIN32
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc
index d13a7fc7c21..7be82db2e30 100644
--- a/storage/connect/ha_connect.cc
+++ b/storage/connect/ha_connect.cc
@@ -3070,6 +3070,8 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
if ((iscol= args[i]->type() == COND::FIELD_ITEM)) {
const char *fnm;
+ char buf[MAX_FIELD_WIDTH];
+ String strColumn(buf, sizeof(buf), system_charset_info);
ha_field_option_struct *fop;
Item_field *pField= (Item_field *)args[i];
@@ -3095,8 +3097,14 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
return NULL;
} else {
bool h;
-
fnm= filp->Chk(pField->field->field_name.str, &h);
+ if (tty == TYPE_AM_MYSQL && !(x || ismul))
+ {
+ strColumn.length(0);
+ strColumn.qs_append(STRING_WITH_LEN("`"));
+ strColumn.qs_append(fnm, strlen(fnm));
+ strColumn.append(STRING_WITH_LEN("`"));
+ }
if (h && i && !ishav)
return NULL; // Having should be col VOP arg
@@ -3110,9 +3118,11 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
htrc("Field name=%s\n", pField->field->field_name.str);
htrc("Field type=%d\n", pField->field->type());
htrc("Field_type=%d\n", args[i]->field_type());
- } // endif trace
-
- strcat((ishav ? havg : body), fnm);
+ } // endif trace
+ if (tty == TYPE_AM_MYSQL && !(x || ismul))
+ strcat((ishav ? havg : body), strColumn.ptr());
+ else
+ strcat((ishav ? havg : body), fnm);
} else if (args[i]->type() == COND::FUNC_ITEM) {
if (tty == TYPE_AM_MYSQL) {
if (!CheckCond(g, filp, args[i]))
diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h
index 090f8343e1e..71ceb7974ba 100644
--- a/storage/connect/ha_connect.h
+++ b/storage/connect/ha_connect.h
@@ -555,3 +555,25 @@ public:
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
bool MongoEnabled(void);
#endif // JAVA_SUPPORT || CMGO_SUPPORT
+
+/* This is a hack for ASAN
+ * Libraries such as libxml2 and libodbc do not like being unloaded before
+ * exit and will show as a leak in ASAN with no stack trace (as the plugin
+ * has been unloaded from memory).
+ *
+ * The below is designed to trick the compiler into adding a "UNIQUE" symbol
+ * which can be seen using:
+ * readelf -s storage/connect/ha_connect.so | grep UNIQUE
+ *
+ * Having this symbol means that the plugin remains in memory after dlclose()
+ * has been called. Thereby letting the libraries clean up properly.
+ */
+#if defined(__SANITIZE_ADDRESS__)
+__attribute__((__used__))
+inline int dummy(void)
+{
+ static int d;
+ d++;
+ return d;
+}
+#endif
diff --git a/storage/connect/jdbconn.cpp b/storage/connect/jdbconn.cpp
index fc22b7033be..0ba1f56aa50 100644
--- a/storage/connect/jdbconn.cpp
+++ b/storage/connect/jdbconn.cpp
@@ -451,8 +451,14 @@ PQRYRES JDBCSrcCols(PGLOBAL g, PCSZ src, PJPARM sjp)
if (strstr(src, "%s")) {
// Place holder for an eventual where clause
- sqry = (char*)PlugSubAlloc(g, NULL, strlen(src) + 2);
- sprintf(sqry, src, "1=1"); // dummy where clause
+ size_t sqry_size = strlen(src) + 2;
+ sqry = (char*)PlugSubAlloc(g, NULL, sqry_size);
+ // Function PlugSubAlloc(...) recalculate string size
+ // while allocate memory - it rounds size up size to multiple of 8
+ // we need to know the real allocated size
+ // to use it in sprintf(...)
+ const int sqry_real_allocated_size = ROUNDUP_TO_8(sqry_size);
+ snprintf(sqry, sqry_real_allocated_size, src, "1=1"); // dummy where clause
} else
sqry = (char*)src;
diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp
index f27f5a9d55b..4078a03830a 100644
--- a/storage/connect/json.cpp
+++ b/storage/connect/json.cpp
@@ -1023,13 +1023,13 @@ bool JDOC::SerializeValue(PJVAL jvp)
case TYPE_DTM:
return js->Escape(jvp->Strp);
case TYPE_INTG:
- sprintf(buf, "%d", jvp->N);
+ snprintf(buf, sizeof(buf), "%d", jvp->N);
return js->WriteStr(buf);
case TYPE_BINT:
- sprintf(buf, "%lld", jvp->LLn);
+ snprintf(buf, sizeof(buf), "%lld", jvp->LLn);
return js->WriteStr(buf);
case TYPE_DBL: // dfp to limit to the default number of decimals
- sprintf(buf, "%.*f", MY_MIN(jvp->Nd, dfp), jvp->F);
+ snprintf(buf, sizeof(buf), "%.*f", MY_MIN(jvp->Nd, dfp), jvp->F);
return js->WriteStr(buf);
case TYPE_NULL:
return js->WriteStr("null");
diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp
index b29cc6a65a4..b09838beb97 100644
--- a/storage/connect/jsonudf.cpp
+++ b/storage/connect/jsonudf.cpp
@@ -908,7 +908,7 @@ my_bool JSNX::LocateArray(PGLOBAL g, PJAR jarp)
for (int i = 0; i < jarp->size() && !Found; i++) {
Jp->N = m;
- sprintf(s, "[%d]", i + B);
+ snprintf(s, sizeof(s), "[%d]", i + B);
if (Jp->WriteStr(s))
return true;
@@ -1189,7 +1189,7 @@ my_bool JSNX::AddPath(void) {
for (int i = 0; i <= I; i++) {
if (Jpnp[i].Type == TYPE_JAR) {
- sprintf(s, "[%d]", Jpnp[i].N + B);
+ snprintf(s, sizeof(s), "[%d]", Jpnp[i].N + B);
if (Jp->WriteStr(s))
return true;
diff --git a/storage/connect/libdoc.cpp b/storage/connect/libdoc.cpp
index 60e24841a94..14e1e44895c 100644
--- a/storage/connect/libdoc.cpp
+++ b/storage/connect/libdoc.cpp
@@ -290,46 +290,8 @@ if (!rc)
/******************************************************************/
/* XML library cleanup function. */
/******************************************************************/
-/*
- This is a copy of xmlCleanupParser() from the libxml2 sources
- with xmlResetLastError() commented.
-
- xmlResetLastError() called from the original xmlCleanupParser() causes
- valgrind to report memory leaks. This happens because
- ha_initialize_handlerton() is called from the main thread in mysqld.cc,
- while ha_finalize_handlerton() is called from a non-main thread.
- libxml2 gets confused because of xmlInitParser() and xmlCleanupParser()
- being called from the different threads.
-
- Perhaps the code in mysqld.cc should eventually be modified
- to shutdown plugins from the main thread.
-*/
-static void
-xmlCleanupParser_replacement(void)
- {
- xmlCleanupCharEncodingHandlers();
-#ifdef LIBXML_CATALOG_ENABLED
- xmlCatalogCleanup();
-#endif
- xmlDictCleanup();
- xmlCleanupInputCallbacks();
-#ifdef LIBXML_OUTPUT_ENABLED
- xmlCleanupOutputCallbacks();
-#endif
-#ifdef LIBXML_SCHEMAS_ENABLED
- xmlSchemaCleanupTypes();
- xmlRelaxNGCleanupTypes();
-#endif
- //xmlResetLastError();
- xmlCleanupGlobals();
- xmlCleanupThreads(); /* must be last if called not from the main thread */
- xmlCleanupMemory();
- }
-
-
void XmlCleanupParserLib(void)
{
- xmlCleanupParser_replacement();
} // end of XmlCleanupParserLib
/******************************************************************/
diff --git a/storage/connect/mysql-test/connect/r/mysql.result b/storage/connect/mysql-test/connect/r/mysql.result
index 83c2bc0abb5..918256ac395 100644
--- a/storage/connect/mysql-test/connect/r/mysql.result
+++ b/storage/connect/mysql-test/connect/r/mysql.result
@@ -304,5 +304,27 @@ INSERT INTO t2 VALUES (10),(20),(30),(40);
DROP TABLE t2;
DROP TABLE t1;
#
+# MDEV-28533 CONNECT engine does not quote columns involved in WHERE clause
+#
+CREATE TABLE t1 (id int, `spaced col` varchar(10),`nospace` varchar(10));
+insert into t1 values (1,1,'x1'),(2,'C-003','x2');
+SELECT * from t1;
+id spaced col nospace
+1 1 x1
+2 C-003 x2
+CREATE TABLE t2 (id int, `spaced col` varchar(10), `nospace` varchar(10)) ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=PORT';
+SELECT * from t2;
+id spaced col nospace
+1 1 x1
+2 C-003 x2
+SELECT `id` FROM t2 WHERE t2.`nospace` = 'x1';
+id
+1
+SELECT `id` FROM t2 WHERE t2.`spaced col` = 'C-003';
+id
+2
+DROP TABLE t1;
+DROP TABLE t2;
+#
# End of 10.3 tests
#
diff --git a/storage/connect/mysql-test/connect/r/odbc_postgresql.result b/storage/connect/mysql-test/connect/r/odbc_postgresql.result
index dc23dbdb990..fd23197c37f 100644
--- a/storage/connect/mysql-test/connect/r/odbc_postgresql.result
+++ b/storage/connect/mysql-test/connect/r/odbc_postgresql.result
@@ -17,6 +17,7 @@ mtr public t2 TABLE
mtr public v1 VIEW
mtr schema1 t1 TABLE
mtr schema1 t2 TABLE
+mtr schema1 t3 TABLE
mtr schema1 v1 VIEW
DROP TABLE t1;
# All tables in all schemas
@@ -28,6 +29,7 @@ mtr public t2 TABLE
mtr public v1 VIEW
mtr schema1 t1 TABLE
mtr schema1 t2 TABLE
+mtr schema1 t3 TABLE
mtr schema1 v1 VIEW
DROP TABLE t1;
# All tables in all schemas
@@ -39,6 +41,7 @@ mtr public t2 TABLE
mtr public v1 VIEW
mtr schema1 t1 TABLE
mtr schema1 t2 TABLE
+mtr schema1 t3 TABLE
mtr schema1 v1 VIEW
DROP TABLE t1;
# All tables in the default schema ("public")
@@ -101,6 +104,8 @@ mtr public t2 a 4 int4 10 4 0 10 0
mtr public v1 a 4 int4 10 4 0 10 1
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0
+mtr schema1 t3 a 1 bpchar 10 40 NULL NULL 0
+mtr schema1 t3 b 1 bpchar 10 40 NULL NULL 0
mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1
DROP TABLE t1;
# All columns in the schemas "public" and "schema1"
@@ -112,6 +117,8 @@ mtr public t2 a 4 int4 10 4 0 10 0
mtr public v1 a 4 int4 10 4 0 10 1
mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0
mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0
+mtr schema1 t3 a 1 bpchar 10 40 NULL NULL 0
+mtr schema1 t3 b 1 bpchar 10 40 NULL NULL 0
mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1
DROP TABLE t1;
# All tables "t1" in all schemas
@@ -195,7 +202,7 @@ SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(10) NOT NULL
-) ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.t1' `DATA_CHARSET`='utf8'
+) ENGINE=CONNECT DEFAULT CHARSET=utf8mb3 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.t1' `DATA_CHARSET`='utf8'
SELECT * FROM t1;
a
aaa
@@ -206,7 +213,7 @@ CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
- `a` char(10) CHARACTER SET utf8 NOT NULL
+ `a` char(10) CHARACTER SET utf8mb3 NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
a
@@ -230,7 +237,7 @@ SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(10) DEFAULT NULL
-) ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.v1' `DATA_CHARSET`='utf8'
+) ENGINE=CONNECT DEFAULT CHARSET=utf8mb3 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.v1' `DATA_CHARSET`='utf8'
SELECT * FROM t1;
a
aaa
@@ -241,7 +248,7 @@ CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
- `a` char(10) CHARACTER SET utf8 DEFAULT NULL
+ `a` char(10) CHARACTER SET utf8mb3 DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
a
@@ -265,7 +272,7 @@ SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(10) NOT NULL
-) ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.t2' `DATA_CHARSET`='utf8'
+) ENGINE=CONNECT DEFAULT CHARSET=utf8mb3 CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' `TABLE_TYPE`='ODBC' `TABNAME`='schema1.t2' `DATA_CHARSET`='utf8'
SELECT * FROM t1;
a
xxx
@@ -276,7 +283,7 @@ CREATE TABLE t2 AS SELECT * FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
- `a` char(10) CHARACTER SET utf8 NOT NULL
+ `a` char(10) CHARACTER SET utf8mb3 NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
a
@@ -294,3 +301,8 @@ zzz
ÄÖÜ
DROP VIEW v1;
DROP TABLE t1;
+CREATE TABLE t1 (a VARCHAR(6), b VARCHAR(6), PRIMARY KEY(a, b)) ENGINE=CONNECT TABNAME='schema1.t3' CHARSET=utf8 DATA_CHARSET=utf8 TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr';
+DELETE FROM t1 WHERE a='20';
+Warnings:
+Note 1105 schema1.t3: 0 affected rows
+DROP TABLE t1;
diff --git a/storage/connect/mysql-test/connect/t/mysql.test b/storage/connect/mysql-test/connect/t/mysql.test
index 451de29c0b0..ce76a4665d5 100644
--- a/storage/connect/mysql-test/connect/t/mysql.test
+++ b/storage/connect/mysql-test/connect/t/mysql.test
@@ -484,5 +484,25 @@ DROP TABLE t2;
DROP TABLE t1;
--echo #
+--echo # MDEV-28533 CONNECT engine does not quote columns involved in WHERE clause
+--echo #
+
+CREATE TABLE t1 (id int, `spaced col` varchar(10),`nospace` varchar(10));
+insert into t1 values (1,1,'x1'),(2,'C-003','x2');
+
+SELECT * from t1;
+
+--replace_result $PORT PORT
+--eval CREATE TABLE t2 (id int, `spaced col` varchar(10), `nospace` varchar(10)) ENGINE=CONNECT TABLE_TYPE=MYSQL DBNAME='test' TABNAME='t1' OPTION_LIST='host=localhost,user=root,port=$PORT'
+
+SELECT * from t2;
+SELECT `id` FROM t2 WHERE t2.`nospace` = 'x1';
+SELECT `id` FROM t2 WHERE t2.`spaced col` = 'C-003';
+
+
+DROP TABLE t1;
+DROP TABLE t2;
+
+--echo #
--echo # End of 10.3 tests
--echo #
diff --git a/storage/connect/mysql-test/connect/t/odbc_postgresql.sql b/storage/connect/mysql-test/connect/t/odbc_postgresql.sql
index 1c302294393..a795817a4d3 100644
--- a/storage/connect/mysql-test/connect/t/odbc_postgresql.sql
+++ b/storage/connect/mysql-test/connect/t/odbc_postgresql.sql
@@ -25,3 +25,6 @@ INSERT INTO schema1.t1 VALUES ('aaa'),('bbb'),('ccc'),('яяя');
CREATE VIEW schema1.v1 AS SELECT * FROM schema1.t1;
CREATE TABLE schema1.t2 (a CHAR(10) NOT NULL);
INSERT INTO schema1.t2 VALUES ('xxx'),('yyy'),('zzz'),('ÄÖÜ');
+CREATE TABLE schema1.t3 (a CHAR(10) NOT NULL, b CHAR(10) NOT NULL);
+INSERT INTO schema1.t3 VALUES ('xxx', 'aaa'),('yyy', 'bbb'),('zzz', 'ccc'),('ÄÖÜ', 'яяя');
+
diff --git a/storage/connect/mysql-test/connect/t/odbc_postgresql.test b/storage/connect/mysql-test/connect/t/odbc_postgresql.test
index 7fc16130713..86597423d04 100644
--- a/storage/connect/mysql-test/connect/t/odbc_postgresql.test
+++ b/storage/connect/mysql-test/connect/t/odbc_postgresql.test
@@ -205,3 +205,9 @@ CREATE VIEW v1 AS SELECT * FROM t1;
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;
+
+# MDEV-25767 DELETE with WHERE condition crashes when two columns used for
+# pkey
+CREATE TABLE t1 (a VARCHAR(6), b VARCHAR(6), PRIMARY KEY(a, b)) ENGINE=CONNECT TABNAME='schema1.t3' CHARSET=utf8 DATA_CHARSET=utf8 TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr';
+DELETE FROM t1 WHERE a='20';
+DROP TABLE t1;
diff --git a/storage/connect/plugutil.cpp b/storage/connect/plugutil.cpp
index d131482ef94..6fb40c92a1b 100644
--- a/storage/connect/plugutil.cpp
+++ b/storage/connect/plugutil.cpp
@@ -371,13 +371,13 @@ char *PlugReadMessage(PGLOBAL g, int mid, char *m)
PlugSetPath(msgfile, NULL, buff, msg_path);
if (!(mfile = fopen(msgfile, "rt"))) {
- sprintf(stmsg, "Fail to open message file %-.256s", msgfile);
+ snprintf(stmsg, sizeof(stmsg), "Fail to open message file %s", msgfile);
goto err;
} // endif mfile
for (;;)
if (!fgets(buff, 256, mfile)) {
- sprintf(stmsg, "Cannot get message %d %-.256s", mid, SVP(m));
+ snprintf(stmsg, sizeof(stmsg), "Cannot get message %d %s", mid, SVP(m));
goto fin;
} else
if (atoi(buff) == mid)
@@ -386,7 +386,7 @@ char *PlugReadMessage(PGLOBAL g, int mid, char *m)
if (sscanf(buff, " %*d %.31s \"%.255[^\"]", msgid, stmsg) < 2) {
// Old message file
if (!sscanf(buff, " %*d \"%.255[^\"]", stmsg)) {
- sprintf(stmsg, "Bad message file for %d %-.256s", mid, SVP(m));
+ snprintf(stmsg, sizeof(stmsg), "Bad message file for %d %s", mid, SVP(m));
goto fin;
} else
m = NULL;
@@ -425,17 +425,18 @@ char *PlugGetMessage(PGLOBAL g, int mid)
if (n == 0) {
DWORD rc = GetLastError();
- msg = (char*)PlugSubAlloc(g, NULL, 512); // Extend buf allocation
- n = sprintf(msg, "Message %d, rc=%d: ", mid, rc);
+ const int BUF_SIZE= 512;
+ msg = (char*)PlugSubAlloc(g, NULL, BUF_SIZE); // Extend buf allocation
+ n = snprintf(msg, BUF_SIZE, "Message %d, rc=%d: ", mid, rc);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, rc, 0,
- (LPTSTR)(msg + n), 512 - n, NULL);
+ (LPTSTR)(msg + n), BUF_SIZE - n, NULL);
return msg;
} // endif n
#else // ALL
if (!GetRcString(mid, stmsg, 200))
- sprintf(stmsg, "Message %d not found", mid);
+ snprintf(stmsg, sizeof(stmsg) "Message %d not found", mid);
#endif // ALL
if (g) {
@@ -564,7 +565,7 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size)
/*******************************************************************/
memp = g->Sarea;
- size = ((size + 7) / 8) * 8; /* Round up size to multiple of 8 */
+ size = ROUNDUP_TO_8(size); /* Round up size to multiple of 8 */
pph = (PPOOLHEADER)memp;
if (trace(16))
diff --git a/storage/connect/tabbson.cpp b/storage/connect/tabbson.cpp
index b69618a60cb..4cbb0e44e19 100644
--- a/storage/connect/tabbson.cpp
+++ b/storage/connect/tabbson.cpp
@@ -477,7 +477,7 @@ bool BSONDISC::Find(PGLOBAL g, PBVAL jvp, PCSZ key, int j)
n = sizeof(fmt) - (strlen(fmt) + 1);
if (!tdp->Xcol || stricmp(tdp->Xcol, key)) {
- sprintf(buf, "%d", k);
+ snprintf(buf, sizeof(buf), "%d", k);
if (tdp->Uri) {
strncat(strncat(fmt, sep, n), buf, n - strlen(sep));
@@ -798,7 +798,7 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
break;
default:
- sprintf(G->Message, "Unsupported column type %d", vp->GetType());
+ snprintf(G->Message, sizeof(G->Message), "Unsupported column type %d", vp->GetType());
throw 888;
} // endswitch Type
diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp
index fb9168f3b88..d60cd039951 100644
--- a/storage/connect/tabodbc.cpp
+++ b/storage/connect/tabodbc.cpp
@@ -553,7 +553,7 @@ bool TDBODBC::OpenDB(PGLOBAL g)
if (Memory < 3) {
// Method will depend on cursor type
- if ((Rbuf = Ocp->Rewind(Query->GetStr(), (PODBCCOL)Columns)) < 0) {
+ if (Query && (Rbuf = Ocp->Rewind(Query->GetStr(), (PODBCCOL)Columns)) < 0) {
if (Mode != MODE_READX) {
Ocp->Close();
return true;
diff --git a/storage/connect/tabwmi.cpp b/storage/connect/tabwmi.cpp
index f90ff98ca35..935d21c59c9 100644
--- a/storage/connect/tabwmi.cpp
+++ b/storage/connect/tabwmi.cpp
@@ -810,7 +810,7 @@ void WMICOL::ReadColumn(PGLOBAL g)
char buf[24];
int rc = VariantTimeToSystemTime(Prop.date, &stm);
- sprintf(buf, "%02d/%02d/%d %02d:%02d:%02d",
+ snprintf(buf, sizeof(buf), "%02d/%02d/%d %02d:%02d:%02d",
stm.wDay, stm.wMonth, stm.wYear,
stm.wHour, stm.wMinute, stm.wSecond);
Value->SetValue_psz(buf);
diff --git a/storage/connect/valblk.cpp b/storage/connect/valblk.cpp
index 7d7da5b6252..528c4abf3db 100644
--- a/storage/connect/valblk.cpp
+++ b/storage/connect/valblk.cpp
@@ -604,7 +604,7 @@ int TYPBLK<TYPE>::GetMaxLength(void)
int i, n, m;
for (i = n = 0; i < Nval; i++) {
- m = sprintf(buf, Fmt, UnalignedRead(i));
+ m = snprintf(buf, sizeof(buf), Fmt, UnalignedRead(i));
n = MY_MAX(n, m);
} // endfor i