Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed a segfault in sqlite2 driver.
stmt_next() overwrote the private field in stmt.
  • Loading branch information
Johannes Thoma authored and lge committed Nov 4, 2010
1 parent 91cefe2 commit 5d660f7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion csync2.h
Expand Up @@ -162,8 +162,8 @@ extern const void * csync_db_colblob(void *stmtx,int col);

#define SQL_END \
} \
csync_db_fin(SQL_VM, SQL_ERR); \
} \
csync_db_fin(SQL_VM, SQL_ERR); \
}

extern int db_blocking_mode;
Expand Down
3 changes: 3 additions & 0 deletions db_mysql.c
Expand Up @@ -53,11 +53,14 @@ static void *dl_handle;

static void db_mysql_dlopen(void)
{
csync_debug(1, "Opening shared library libmysqlclient.so\n");
dl_handle = dlopen("libmysqlclient.so", RTLD_LAZY);
if (dl_handle == NULL) {
csync_fatal("Could not open libmysqlclient.so: %s\nPlease install Mysql client library (libmysqlclient) or use other database (sqlite, postgres)\n", dlerror());
}

csync_debug(1, "Reading symbols from shared library libmysqlclient.so\n");

LOOKUP_SYMBOL(dl_handle, mysql_init);
LOOKUP_SYMBOL(dl_handle, mysql_real_connect);
LOOKUP_SYMBOL(dl_handle, mysql_errno);
Expand Down
3 changes: 3 additions & 0 deletions db_postgres.c
Expand Up @@ -58,10 +58,13 @@ static void *dl_handle;

static void db_postgres_dlopen(void)
{
csync_debug(1, "Opening shared library libpq.so\n");

dl_handle = dlopen("libpq.so", RTLD_LAZY);
if (dl_handle == NULL) {
csync_fatal("Could not open libpq.so: %s\nPlease install postgres client library (libpg) or use other database (sqlite, mysql)\n", dlerror());
}
csync_debug(1, "Reading symbols from shared library libpq.so\n");

LOOKUP_SYMBOL(dl_handle, PQconnectdb);
LOOKUP_SYMBOL(dl_handle, PQstatus);
Expand Down
7 changes: 5 additions & 2 deletions db_sqlite.c
Expand Up @@ -58,10 +58,13 @@ static void *dl_handle;

static void db_sqlite3_dlopen(void)
{
dl_handle = dlopen("libsqlite3.so", RTLD_LAZY);
csync_debug(1, "Opening shared library libsqlite.so\n");

dl_handle = dlopen("libsqlite.so", RTLD_LAZY);
if (dl_handle == NULL) {
csync_fatal("Could not open libsqlite3.so: %s\nPlease install sqlite3 client library (libsqlite3) or use other database (postgres, mysql)\n", dlerror());
csync_fatal("Could not open libsqlite.so: %s\nPlease install sqlite3 client library (libsqlite3) or use other database (postgres, mysql)\n", dlerror());
}
csync_debug(1, "Reading symbols from shared library libsqlite.so\n");

LOOKUP_SYMBOL(dl_handle, sqlite3_open);
LOOKUP_SYMBOL(dl_handle, sqlite3_close);
Expand Down
9 changes: 6 additions & 3 deletions db_sqlite2.c
Expand Up @@ -55,10 +55,13 @@ static void *dl_handle;

static void db_sqlite_dlopen(void)
{
dl_handle = dlopen("libsqlite3.so", RTLD_LAZY);
csync_debug(1, "Opening shared library libsqlite.so\n");

dl_handle = dlopen("libsqlite.so", RTLD_LAZY);
if (dl_handle == NULL) {
csync_fatal("Could not open libsqlite3.so: %s\nPlease install sqlite3 client library (libsqlite3) or use other database (postgres, mysql)\n", dlerror());
csync_fatal("Could not open libsqlite.so: %s\nPlease install sqlite client library (libsqlite) or use other database (postgres, mysql)\n", dlerror());
}
csync_debug(1, "Opening shared library libsqlite.so\n");

LOOKUP_SYMBOL(dl_handle, sqlite_open);
LOOKUP_SYMBOL(dl_handle, sqlite_close);
Expand Down Expand Up @@ -190,7 +193,7 @@ int db_sqlite2_stmt_next(db_stmt_p stmt)
int columns;

int rc = f.sqlite_step_fn(sqlite_stmt, &columns, &values, &names);
stmt->private = values;
stmt->private2 = values;
/* TODO error mapping */
return rc; // == SQLITE_ROW;
}
Expand Down
2 changes: 1 addition & 1 deletion dl.h
Expand Up @@ -6,7 +6,7 @@
#define LOOKUP_SYMBOL(dl_handle, sym) \
f.sym ## _fn = dlsym(dl_handle, #sym); \
if ((f.sym ## _fn) == NULL) { \
csync_fatal ("Could not lookup %s in libpq.so: %s\n", #sym, dlerror()); \
csync_fatal ("Could not lookup %s in shared library: %s\n", #sym, dlerror()); \
}

#endif

0 comments on commit 5d660f7

Please sign in to comment.