Skip to content

Added check for null pointer before accessing and leaving SQLite mutex.#2276

Merged
aleks-f merged 2 commits intopocoproject:developfrom
jiajen:sqlite-fix-mutex-null-deref
Apr 10, 2018
Merged

Added check for null pointer before accessing and leaving SQLite mutex.#2276
aleks-f merged 2 commits intopocoproject:developfrom
jiajen:sqlite-fix-mutex-null-deref

Conversation

@jiajen
Copy link
Copy Markdown
Contributor

@jiajen jiajen commented Apr 9, 2018

A null pointer dereference occurs when a SQLite Session fails to be constructed. This can be recreated with the following code:

try
{
	Poco::SQL::Session tmp(Poco::SQL::SQLite::Connector::KEY, "\\/some\\/invalid\\/path\\/sqlite.db", 1);
}
catch (Poco::SQL::ConnectionFailedException&)
{
}

The issue occurs when the database cannot be created and attempts to throw an exception. However, since all exceptions invoke a SQLite mutex (since the fix for issue #2012), sqlite3_db_mutex(pDB) causes a segmentation fault when pDB is null which can occur if the database cannot be created. Checking for a null pointer before entering and leaving the SQLite mutex solves the problem.

Utility::SQLiteMutex::SQLiteMutex(sqlite3* pDB)
{
sqlite3_mutex_enter(_pMutex);
_pMutex = (pDB) ? sqlite3_db_mutex(pDB) : NULL;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple of things:

  1. this is ok, but please leave it in initialization
  2. use 0, not NULL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strictly speaking nullptr would be the right thing to do, but since 1.x releases do not yet unconditionally support c++11, let's have 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the changes. Thanks for pointing out!

@aleks-f
Copy link
Copy Markdown
Member

aleks-f commented Apr 9, 2018

@jiajen thanks, just so it is properly tracked, would you mind opening issue and sending the same fix to poco-1.9.1 branch

@aleks-f aleks-f added this to the Release 2.0.0 milestone Apr 10, 2018
@aleks-f aleks-f added the fixed label Apr 10, 2018
@aleks-f aleks-f merged commit 49aa907 into pocoproject:develop Apr 10, 2018
@jiajen jiajen deleted the sqlite-fix-mutex-null-deref branch April 11, 2018 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants