Hi! I found a potential null dereference issue using the Svace static analyzer.
Problem
IdoMysqlConnection::OnConfigLoaded() obtains the create_mysql_shim function from the MySQL shim library using Library::GetSymbolAddress() and immediately calls the returned function pointer:
auto create_mysql_shim =
shimLibrary.GetSymbolAddress<create_mysql_shim_ptr>("create_mysql_shim");
m_Mysql.reset(create_mysql_shim());
Library::GetSymbolAddress() uses dlsym() on Unix systems and GetProcAddress() on Windows. These functions may return nullptr when the requested symbol is not found.
The returned function pointer is not checked before being called. If create_mysql_shim is missing from the loaded library, the code attempts to call a null function pointer, which results in undefined behavior and may terminate the process.
The library itself is handled separately: failure to load the library causes Library to throw an exception. The issue concerns the case where the library is loaded successfully but the expected symbol is unavailable.
Author T.Mishin
Hi! I found a potential null dereference issue using the Svace static analyzer.
Problem
IdoMysqlConnection::OnConfigLoaded() obtains the create_mysql_shim function from the MySQL shim library using Library::GetSymbolAddress() and immediately calls the returned function pointer:
auto create_mysql_shim =
shimLibrary.GetSymbolAddress<create_mysql_shim_ptr>("create_mysql_shim");
m_Mysql.reset(create_mysql_shim());
Library::GetSymbolAddress() uses dlsym() on Unix systems and GetProcAddress() on Windows. These functions may return nullptr when the requested symbol is not found.
The returned function pointer is not checked before being called. If create_mysql_shim is missing from the loaded library, the code attempts to call a null function pointer, which results in undefined behavior and may terminate the process.
The library itself is handled separately: failure to load the library causes Library to throw an exception. The issue concerns the case where the library is loaded successfully but the expected symbol is unavailable.
Author T.Mishin