Menu

#85 [cppdb] segfault when using prepared statement with statement that does nothing

cppcms-v1.0.x
open
nobody
cppdb (9)
1
2014-10-30
2013-01-07
Anonymous
No

When executing a set of query , if at one moment a query contains nothing (i.e empty string/SQL comment only/empty spaces) the execute will generate a segfault here is a sample code

int SqliteModel::import_sql_file(
const std::string &sqlFilePath
) {
try {
std::ifstream f(sqlFilePath.c_str());
std::string fileStr(
(std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>()
);
sqliteDb << fileStr << cppdb::exec;
size_t current = 0;
size_t next = -1;
do
{
current = next + 1;
next = fileStr.find_first_of( ";", current );
std::string tmpRequest = fileStr.substr( current, next - current );
sqliteDb << tmpRequest << cppdb::exec;
} while (next != std::string::npos);</char></char>

} catch(std::exception const &e) {
    BOOSTER_ERROR("cppcms") << e.what();
    return 1;
}
return 0;

}

and it will segfault (no exception, a old goold segfault) when I try to execute a string containing nothing or a comment or a set of space with nothing less
the backtrace generates

0 0xb61eee96 in sqlite3_clear_bindings () from /usr/lib/i386-linux-gnu/libsqlite3.so.0

1 0xb7c6433a in cppdb::sqlite3_backend::statement::reset (this=0x80710c8)

at /home/allan/Desktop/projet/cppdb-0.3.0/drivers/sqlite3_backend.cpp:226

2 0xb7d81b95 in cppdb::backend::statements_cache::put (this=0x805d37c, p_in=0x80710c8)

at /home/allan/Desktop/projet/cppdb-0.3.0/src/backend.cpp:146

3 0xb7d81d43 in cppdb::backend::statement::dispose (p=0x80710c8) at /home/allan/Desktop/projet/cppdb-0.3.0/src/backend.cpp:54

4 0xb7d8bbdb in reset (v=0x0, this=0xbffff43c) at /home/allan/Desktop/projet/cppdb-0.3.0/./cppdb/ref_ptr.h:109

5 cppdb::statement::~statement (this=0xbffff438, __in_chrg=<optimized out="">)</optimized>

at /home/allan/Desktop/projet/cppdb-0.3.0/src/frontend.cpp:218

6 0x080536fb in models::SqliteModel::import_sql_file(std::string const&) ()

7 0x0804f6ec in main ()

which is in line 226 of sqlite3_backend of cppdb

sqlite3_clear_bindings(st_);

st_ being a NULL pointer (0x0)

Discussion

Anonymous
Anonymous

Add attachments
Cancel