From: Kern Sibbald Date: Sun, 6 Dec 2009 19:33:05 +0000 (+0100) Subject: Attempt to fix SQLite seg fault when listing fields X-Git-Tag: Release-5.0.0~183 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=20c9021ff66b162ba6ef5871754ce6f20b887857;p=bacula%2Fbacula Attempt to fix SQLite seg fault when listing fields --- diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 003036647a..946a87e8fa 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2009 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -356,7 +356,7 @@ bool db_sql_query(B_DB *mdb, const char *query, DB_RESULT_HANDLER *result_handle rh_data.result_handler = result_handler; rh_data.ctx = ctx; stat = sqlite_exec(mdb->db, query, sqlite_result, (void *)&rh_data, &mdb->sqlite_errmsg); - if (stat != 0) { + if (stat != SQLITE_OK) { Mmsg(mdb->errmsg, _("Query failed: %s: ERR=%s\n"), query, sql_strerror(mdb)); db_unlock(mdb); return false; @@ -383,14 +383,17 @@ int my_sqlite_query(B_DB *mdb, const char *cmd) } stat = sqlite_get_table(mdb->db, (char *)cmd, &mdb->result, &mdb->nrow, &mdb->ncolumn, &mdb->sqlite_errmsg); - mdb->row = 0; /* row fetched */ + mdb->row = 0; /* no row fetched yet */ + if (stat != 0) { /* something went wrong */ + mdb->nrow = mdb->ncolumn = 0; + } return stat; } /* Fetch one row at a time */ SQL_ROW my_sqlite_fetch_row(B_DB *mdb) { - if (mdb->row >= mdb->nrow) { + if (!mdb->result || (mdb->row >= mdb->nrow)) { return NULL; } mdb->row++; @@ -425,6 +428,7 @@ void my_sqlite_field_seek(B_DB *mdb, int field) { int i, j; if (mdb->result == NULL) { + mdb->field = 0; return; } /* On first call, set up the fields */ @@ -451,7 +455,9 @@ void my_sqlite_field_seek(B_DB *mdb, int field) } mdb->fields_defined = true; } - if (field > sql_num_fields(mdb) - 1) { + if (sql_num_fields(mdb) <= 0) { + field = 0; + } else if (field > sql_num_fields(mdb) - 1) { field = sql_num_fields(mdb) - 1; } mdb->field = field;