From: Walter Doekes Date: Thu, 3 Nov 2011 20:26:19 +0000 (+0000) Subject: Fix sqlite config driver segfault and broken queries X-Git-Tag: 1.8.9.0-rc1~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5238279e7853a08a70986566fc9c1d1204339b1;p=thirdparty%2Fasterisk.git Fix sqlite config driver segfault and broken queries The sqlite realtime handler assumed you had a static config configured as well. The realtime multientry handler assumed that you weren't using dynamic realtime. (closes issue ASTERISK-18354) (closes issue ASTERISK-18355) Review: https://reviewboard.asterisk.org/r/1561 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@343375 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/res/res_config_sqlite.c b/res/res_config_sqlite.c index b5b8de4ed0..d43c32b2aa 100644 --- a/res/res_config_sqlite.c +++ b/res/res_config_sqlite.c @@ -1055,7 +1055,7 @@ static struct ast_variable * realtime_handler(const char *database, const char * #define QUERY "SELECT * FROM '%q' WHERE%s %q%s '%q'" /* \endcond */ - query = sqlite_mprintf(QUERY, table, !strcmp(config_table, table) ? " commented = 0 AND" : "", params[0], op, vals[0]); + query = sqlite_mprintf(QUERY, table, (config_table && !strcmp(config_table, table)) ? " commented = 0 AND" : "", params[0], op, vals[0]); if (!query) { ast_log(LOG_WARNING, "Unable to allocate SQL query\n"); @@ -1216,10 +1216,10 @@ static struct ast_config *realtime_multi_handler(const char *database, /* \cond DOXYGEN_CAN_PARSE_THIS */ #undef QUERY -#define QUERY "SELECT * FROM '%q' WHERE commented = 0 AND %q%s '%q'" +#define QUERY "SELECT * FROM '%q' WHERE%s %q%s '%q'" /* \endcond */ - if (!(query = sqlite_mprintf(QUERY, table, params[0], op, tmp_str))) { + if (!(query = sqlite_mprintf(QUERY, table, (config_table && !strcmp(config_table, table)) ? " commented = 0 AND" : "", params[0], op, tmp_str))) { ast_log(LOG_WARNING, "Unable to allocate SQL query\n"); ast_config_destroy(cfg); ast_free(params);