You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2021/08/18 15:10:28 UTC

[ignite] branch master updated: IGNITE-15332 CPP: Fix stringop-truncation warning, fix assertions on ODBC error codes - Fixes #9341.

This is an automated email from the ASF dual-hosted git repository.

ivandasch pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 91c4b0d  IGNITE-15332 CPP: Fix stringop-truncation warning, fix assertions on ODBC error codes - Fixes #9341.
91c4b0d is described below

commit 91c4b0dbf927ca8cebc5e4ccb2aff95d2cf47ef1
Author: Ivan Daschinsky <iv...@apache.org>
AuthorDate: Wed Aug 18 18:08:41 2021 +0300

    IGNITE-15332 CPP: Fix stringop-truncation warning, fix assertions on ODBC error codes - Fixes #9341.
    
    Signed-off-by: Ivan Daschinsky <iv...@apache.org>
---
 modules/platforms/cpp/odbc-test/include/test_utils.h   | 18 ++++++++++++++++++
 .../platforms/cpp/odbc-test/src/odbc_test_suite.cpp    |  4 ++--
 .../platforms/cpp/odbc-test/src/queries_ssl_test.cpp   |  5 ++++-
 modules/platforms/cpp/odbc-test/src/streaming_test.cpp |  2 +-
 .../platforms/cpp/odbc-test/src/transaction_test.cpp   |  4 ++--
 5 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/modules/platforms/cpp/odbc-test/include/test_utils.h b/modules/platforms/cpp/odbc-test/include/test_utils.h
index 6cac2af..086504c 100644
--- a/modules/platforms/cpp/odbc-test/include/test_utils.h
+++ b/modules/platforms/cpp/odbc-test/include/test_utils.h
@@ -58,6 +58,24 @@
     }
 
 /**
+ * Copy std::string to buffer.
+ *
+ * @param dst Destination buffer.
+ * @param src Source std::string.
+ * @param n Copy at most n bytes of src.
+ */
+inline void CopyStringToBuffer(char *dst, const std::string& src, size_t n) {
+    if (n == 0) {
+        return;
+    }
+
+    size_t size = std::min(src.size(), n - 1);
+
+    memset(dst + size, '\0', n - size);
+    memcpy(dst, src.c_str(), size);
+}
+
+/**
  * Client ODBC erorr.
  */
 class OdbcClientError : public std::exception
diff --git a/modules/platforms/cpp/odbc-test/src/odbc_test_suite.cpp b/modules/platforms/cpp/odbc-test/src/odbc_test_suite.cpp
index 4a08a18..bef4639 100644
--- a/modules/platforms/cpp/odbc-test/src/odbc_test_suite.cpp
+++ b/modules/platforms/cpp/odbc-test/src/odbc_test_suite.cpp
@@ -434,7 +434,7 @@ namespace ignite
                 key = i + 1;
                 std::string val = GetTestString(i);
 
-                strncpy(strField, val.c_str(), sizeof(strField));
+                CopyStringToBuffer(strField, val, sizeof(strField));
                 strFieldLen = SQL_NTS;
 
                 ret = SQLExecute(stmt);
@@ -512,7 +512,7 @@ namespace ignite
                 i32Fields[i] = GetTestI32Field(seed);
 
                 std::string val = GetTestString(seed);
-                strncpy(strFields.GetData() + 1024 * i, val.c_str(), 1023);
+                CopyStringToBuffer(strFields.GetData() + 1024 * i, val, 1023);
                 strFieldsLen[i] = val.size();
 
                 floatFields[i] = GetTestFloatField(seed);
diff --git a/modules/platforms/cpp/odbc-test/src/queries_ssl_test.cpp b/modules/platforms/cpp/odbc-test/src/queries_ssl_test.cpp
index d66911a..4a6acb2 100644
--- a/modules/platforms/cpp/odbc-test/src/queries_ssl_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/queries_ssl_test.cpp
@@ -131,7 +131,10 @@ BOOST_AUTO_TEST_CASE(TestConnectionSslReject)
     BOOST_REQUIRE_EQUAL(ret, SQL_ERROR);
 
     // Checking that error is the connection error.
-    BOOST_CHECK_EQUAL(std::string("08001"), GetOdbcErrorState(SQL_HANDLE_DBC, dbc));
+    std::set<std::string> codes;
+    codes.insert(std::string("08001")); // Client unable to establish connection.
+    codes.insert(std::string("08S01")); // Communication link failure. Returned on newest UnixODBC.
+    BOOST_CHECK_EQUAL(codes.count(GetOdbcErrorState(SQL_HANDLE_DBC, dbc)), 1);
 }
 
 BOOST_AUTO_TEST_CASE(TestLoginTimeout)
diff --git a/modules/platforms/cpp/odbc-test/src/streaming_test.cpp b/modules/platforms/cpp/odbc-test/src/streaming_test.cpp
index d863e37..a7e6c1c 100644
--- a/modules/platforms/cpp/odbc-test/src/streaming_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/streaming_test.cpp
@@ -117,7 +117,7 @@ struct StreamingTestSuiteFixture : odbc::OdbcTestSuite
             key = i;
             std::string val = GetTestString(i);
 
-            strncpy(strField, val.c_str(), sizeof(strField));
+            CopyStringToBuffer(strField, val, sizeof(strField));
             strFieldLen = SQL_NTS;
 
             ret = SQLExecute(stmt0);
diff --git a/modules/platforms/cpp/odbc-test/src/transaction_test.cpp b/modules/platforms/cpp/odbc-test/src/transaction_test.cpp
index a15f8f5..3f4ab75 100644
--- a/modules/platforms/cpp/odbc-test/src/transaction_test.cpp
+++ b/modules/platforms/cpp/odbc-test/src/transaction_test.cpp
@@ -101,7 +101,7 @@ struct TransactionTestSuiteFixture : public odbc::OdbcTestSuite
 
         ODBC_THROW_ON_ERROR(ret, SQL_HANDLE_STMT, stmt);
 
-        strncpy(strField, value.c_str(), sizeof(strField));
+        CopyStringToBuffer(strField, value, sizeof(strField));
         strFieldLen = SQL_NTS;
 
         ret = SQLExecute(stmt);
@@ -161,7 +161,7 @@ struct TransactionTestSuiteFixture : public odbc::OdbcTestSuite
 
         ODBC_THROW_ON_ERROR(ret, SQL_HANDLE_STMT, stmt);
 
-        strncpy(strField, value.c_str(), sizeof(strField));
+        CopyStringToBuffer(strField, value, sizeof(strField));
         strFieldLen = SQL_NTS;
 
         ret = SQLExecute(stmt);