From 92bda1df976111983bf46fd96b13d433edecd145 Mon Sep 17 00:00:00 2001 From: nbertoldo Date: Thu, 29 Aug 2024 17:33:38 -0300 Subject: [PATCH] fix: fixed dbsync segmentation fault --- src/common/dbsync/src/sqlite/isqlite_wrapper.h | 4 ++-- .../dbsync/src/sqlite/sqlite_dbengine.cpp | 12 ++++++------ src/common/dbsync/src/sqlite/sqlite_dbengine.h | 14 +++++++------- .../dbsync/src/sqlite/sqlite_wrapper.cpp | 4 ++-- src/common/dbsync/src/sqlite/sqlite_wrapper.h | 2 +- .../dbsync/src/sqlite/sqlite_wrapper_factory.h | 18 +++++++++--------- src/common/dbsync/tests/sqlite/sqlite_test.cpp | 2 +- .../sqliteWrapper/include/sqliteWrapperTemp.h | 8 ++++---- src/modules/include/modules.hpp | 2 +- src/modules/src/modules.cpp | 3 +-- src/vcpkg.json | 4 ++++ 11 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/common/dbsync/src/sqlite/isqlite_wrapper.h b/src/common/dbsync/src/sqlite/isqlite_wrapper.h index c18f5f486f..72271f881e 100644 --- a/src/common/dbsync/src/sqlite/isqlite_wrapper.h +++ b/src/common/dbsync/src/sqlite/isqlite_wrapper.h @@ -16,7 +16,7 @@ #include #include "db_exception.h" -namespace SQLite +namespace SQLiteLegacy { const constexpr auto MAX_ROWS_ERROR_STRING {"Too Many Rows."}; @@ -90,4 +90,4 @@ namespace SQLite }; -}//namespace SQLite +}//namespace SQLiteLegacy diff --git a/src/common/dbsync/src/sqlite/sqlite_dbengine.cpp b/src/common/dbsync/src/sqlite/sqlite_dbengine.cpp index 60dfa2e343..f8ebda3cc3 100644 --- a/src/common/dbsync/src/sqlite/sqlite_dbengine.cpp +++ b/src/common/dbsync/src/sqlite/sqlite_dbengine.cpp @@ -796,7 +796,7 @@ ColumnType SQLiteDBEngine::columnTypeName(const std::string& type) return retVal; } -bool SQLiteDBEngine::bindJsonData(const std::shared_ptr stmt, +bool SQLiteDBEngine::bindJsonData(const std::shared_ptr stmt, const ColumnData& cd, const nlohmann::json::value_type& valueType, const unsigned int cid) @@ -987,7 +987,7 @@ bool SQLiteDBEngine::getPrimaryKeysFromTable(const std::string& table, return retVal; } -void SQLiteDBEngine::getTableData(std::shared_ptrconst stmt, +void SQLiteDBEngine::getTableData(std::shared_ptrconst stmt, const int32_t index, const ColumnType& type, const std::string& fieldName, @@ -1228,7 +1228,7 @@ void SQLiteDBEngine::deleteRowsbyPK(const std::string& table, } } -void SQLiteDBEngine::bindFieldData(const std::shared_ptr stmt, +void SQLiteDBEngine::bindFieldData(const std::shared_ptr stmt, const int32_t index, const TableField& fieldData) { @@ -1983,14 +1983,14 @@ void SQLiteDBEngine::getFieldValueFromTuple(const Field& value, } } -std::shared_ptrconst SQLiteDBEngine::getStatement(const std::string& sql) +std::shared_ptrconst SQLiteDBEngine::getStatement(const std::string& sql) { std::lock_guard lock(m_stmtMutex); const auto it { std::find_if(m_statementsCache.begin(), m_statementsCache.end(), - [sql](const std::pair>& pair) + [sql](const std::pair>& pair) { return 0 == pair.first.compare(sql); }) @@ -2139,7 +2139,7 @@ void SQLiteDBEngine::updateTableRowCounter(const std::string& table, const long { if (it->second.currentRows + rowModifyCount > it->second.maxRows) { - throw DbSync::max_rows_error { SQLite::MAX_ROWS_ERROR_STRING }; + throw DbSync::max_rows_error { SQLiteLegacy::MAX_ROWS_ERROR_STRING }; } it->second.currentRows += rowModifyCount; diff --git a/src/common/dbsync/src/sqlite/sqlite_dbengine.h b/src/common/dbsync/src/sqlite/sqlite_dbengine.h index c4de7b9e8d..8dddf8c703 100644 --- a/src/common/dbsync/src/sqlite/sqlite_dbengine.h +++ b/src/common/dbsync/src/sqlite/sqlite_dbengine.h @@ -181,7 +181,7 @@ class SQLiteDBEngine final : public DbSync::IDbEngine ColumnType columnTypeName(const std::string& type); - bool bindJsonData(const std::shared_ptr stmt, + bool bindJsonData(const std::shared_ptr stmt, const ColumnData& cd, const nlohmann::json::value_type& valueType, const unsigned int cid); @@ -222,13 +222,13 @@ class SQLiteDBEngine final : public DbSync::IDbEngine void deleteRowsbyPK(const std::string& table, const nlohmann::json& data); - void getTableData(std::shared_ptrconst stmt, + void getTableData(std::shared_ptrconst stmt, const int32_t index, const ColumnType& type, const std::string& fieldName, Row& row); - void bindFieldData(const std::shared_ptr stmt, + void bindFieldData(const std::shared_ptr stmt, const int32_t index, const TableField& fieldData); @@ -295,7 +295,7 @@ class SQLiteDBEngine final : public DbSync::IDbEngine SQLiteDBEngine& operator=(const SQLiteDBEngine&) = delete; - std::shared_ptrconst getStatement(const std::string& sql); + std::shared_ptrconst getStatement(const std::string& sql); std::string getSelectAllQuery(const std::string& table, const TableColumns& tableFields) const; @@ -316,11 +316,11 @@ class SQLiteDBEngine final : public DbSync::IDbEngine const std::function callback = {}); Utils::MapWrapperSafe m_tableFields; - std::deque>> m_statementsCache; + std::deque>> m_statementsCache; const std::shared_ptr m_sqliteFactory; - std::shared_ptr m_sqliteConnection; + std::shared_ptr m_sqliteConnection; std::mutex m_stmtMutex; - std::unique_ptr m_transaction; + std::unique_ptr m_transaction; std::mutex m_maxRowsMutex; std::map m_maxRows; }; diff --git a/src/common/dbsync/src/sqlite/sqlite_wrapper.cpp b/src/common/dbsync/src/sqlite/sqlite_wrapper.cpp index feabdb1227..7f8a549150 100644 --- a/src/common/dbsync/src/sqlite/sqlite_wrapper.cpp +++ b/src/common/dbsync/src/sqlite/sqlite_wrapper.cpp @@ -24,7 +24,7 @@ constexpr auto DB_PERMISSIONS 0640 }; -using namespace SQLite; +using namespace SQLiteLegacy; using ExpandedSQLPtr = std::unique_ptr>; static void checkSqliteResult(const int result, @@ -271,7 +271,7 @@ std::string Statement::expand() std::unique_ptr Statement::column(const int32_t index) { - return std::make_unique(m_stmt, index); + return std::make_unique(m_stmt, index); } int Statement::columnsCount() const diff --git a/src/common/dbsync/src/sqlite/sqlite_wrapper.h b/src/common/dbsync/src/sqlite/sqlite_wrapper.h index c020b97ea5..c23d6b041d 100644 --- a/src/common/dbsync/src/sqlite/sqlite_wrapper.h +++ b/src/common/dbsync/src/sqlite/sqlite_wrapper.h @@ -17,7 +17,7 @@ #include #include -namespace SQLite +namespace SQLiteLegacy { class Connection : public IConnection { diff --git a/src/common/dbsync/src/sqlite/sqlite_wrapper_factory.h b/src/common/dbsync/src/sqlite/sqlite_wrapper_factory.h index 7a1ab215b4..60cf1ac527 100644 --- a/src/common/dbsync/src/sqlite/sqlite_wrapper_factory.h +++ b/src/common/dbsync/src/sqlite/sqlite_wrapper_factory.h @@ -20,9 +20,9 @@ class ISQLiteFactory // LCOV_EXCL_START virtual ~ISQLiteFactory() = default; // LCOV_EXCL_STOP - virtual std::shared_ptr createConnection(const std::string& path) = 0; - virtual std::unique_ptr createTransaction(std::shared_ptr& connection) = 0; - virtual std::unique_ptr createStatement(std::shared_ptr& connection, + virtual std::shared_ptr createConnection(const std::string& path) = 0; + virtual std::unique_ptr createTransaction(std::shared_ptr& connection) = 0; + virtual std::unique_ptr createStatement(std::shared_ptr& connection, const std::string& query) = 0; }; @@ -36,19 +36,19 @@ class SQLiteFactory : public ISQLiteFactory SQLiteFactory(const SQLiteFactory&) = delete; SQLiteFactory& operator=(const SQLiteFactory&) = delete; - std::shared_ptr createConnection(const std::string& path) override + std::shared_ptr createConnection(const std::string& path) override { - return std::make_shared(path); + return std::make_shared(path); } - std::unique_ptr createTransaction(std::shared_ptr& connection) override + std::unique_ptr createTransaction(std::shared_ptr& connection) override { - return std::make_unique(connection); + return std::make_unique(connection); } - std::unique_ptr createStatement(std::shared_ptr& connection, + std::unique_ptr createStatement(std::shared_ptr& connection, const std::string& query) override { - return std::make_unique(connection, query); + return std::make_unique(connection, query); } }; diff --git a/src/common/dbsync/tests/sqlite/sqlite_test.cpp b/src/common/dbsync/tests/sqlite/sqlite_test.cpp index 776bae6898..71f53dc263 100644 --- a/src/common/dbsync/tests/sqlite/sqlite_test.cpp +++ b/src/common/dbsync/tests/sqlite/sqlite_test.cpp @@ -24,7 +24,7 @@ void SQLiteTest::TearDown() }; using ::testing::_; using ::testing::Return; -using namespace SQLite; +using namespace SQLiteLegacy; using namespace DbSync; class ConnectionWrapper: public IConnection diff --git a/src/common/sqliteWrapper/include/sqliteWrapperTemp.h b/src/common/sqliteWrapper/include/sqliteWrapperTemp.h index 280df56af9..9f20db007f 100644 --- a/src/common/sqliteWrapper/include/sqliteWrapperTemp.h +++ b/src/common/sqliteWrapper/include/sqliteWrapperTemp.h @@ -114,7 +114,7 @@ constexpr auto DB_PERMISSIONS }; -namespace SQLite +namespace SQLiteLegacy { const constexpr auto MAX_ROWS_ERROR_STRING {"Too Many Rows."}; @@ -188,9 +188,9 @@ namespace SQLite }; -}//namespace SQLite +}//namespace SQLiteLegacy -using namespace SQLite; +using namespace SQLiteLegacy; using ExpandedSQLPtr = std::unique_ptr>; static void checkSqliteResult(const int result, @@ -228,7 +228,7 @@ static sqlite3_stmt* prepareSQLiteStatement(std::shared_ptr& connec return pStatement; } -namespace SQLite +namespace SQLiteLegacy { class Connection : public IConnection { diff --git a/src/modules/include/modules.hpp b/src/modules/include/modules.hpp index d2323b3d1c..005c8f946f 100644 --- a/src/modules/include/modules.hpp +++ b/src/modules/include/modules.hpp @@ -1,3 +1,3 @@ #pragma once -int modulesExec(); +void modulesExec(); diff --git a/src/modules/src/modules.cpp b/src/modules/src/modules.cpp index 9d1cab8763..43324cbd43 100644 --- a/src/modules/src/modules.cpp +++ b/src/modules/src/modules.cpp @@ -5,7 +5,7 @@ using namespace std; -int modulesExec() { +void modulesExec() { ModuleManager moduleManager; Configuration config; bool running{true}; @@ -20,5 +20,4 @@ int modulesExec() { moduleManager.stop(); - return 0; } diff --git a/src/vcpkg.json b/src/vcpkg.json index 01e1b9522a..b76ad1da3b 100644 --- a/src/vcpkg.json +++ b/src/vcpkg.json @@ -29,6 +29,10 @@ { "name": "lua", "version": "5.3.5#6" + }, + { + "name": "sqlite3", + "version": "3.45.0#0" } ] }