fix(SQLite): SQLite::Connector::open() crashes on db file with non existing directory #2285

This commit is contained in:
Alex Fabijanic 2022-06-21 19:07:19 +02:00
parent 3ca26804e2
commit 4b4be21816
3 changed files with 19 additions and 0 deletions

View File

@ -176,6 +176,8 @@ void SessionImpl::open(const std::string& connect)
rc = sqlite3_open_v2(connectionString().c_str(), &_pDB,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI, NULL);
if (rc == SQLITE_OK) break;
if (!_pDB)
throw ConnectionFailedException(std::string(sqlite3_errstr(rc)));
if (sw.elapsedSeconds() >= tout)
{
Utility::throwException(_pDB, rc);

View File

@ -1376,6 +1376,21 @@ void SQLiteTest::testEmptyDB()
}
void SQLiteTest::testNonexistingDB()
{
try
{
Session tmp (Poco::Data::SQLite::Connector::KEY, "foo/bar/nonexisting.db", 1);
fail("non-existing DB must throw");
}
catch(ConnectionFailedException& ex)
{
return;
}
fail("non-existing DB must throw ConnectionFailedException");
}
void SQLiteTest::testCLOB()
{
std::string lastName("lastname");
@ -3506,6 +3521,7 @@ CppUnit::Test* SQLiteTest::suite()
CppUnit_addTest(pSuite, SQLiteTest, testIllegalRange);
CppUnit_addTest(pSuite, SQLiteTest, testSingleSelect);
CppUnit_addTest(pSuite, SQLiteTest, testEmptyDB);
CppUnit_addTest(pSuite, SQLiteTest, testNonexistingDB);
CppUnit_addTest(pSuite, SQLiteTest, testCLOB);
CppUnit_addTest(pSuite, SQLiteTest, testBLOB);
CppUnit_addTest(pSuite, SQLiteTest, testTuple10);

View File

@ -74,6 +74,7 @@ public:
void testIllegalRange();
void testSingleSelect();
void testEmptyDB();
void testNonexistingDB();
void testCLOB();
void testBLOB();