Skip to content

Commit

Permalink
db_mysql: properly NULL the result pointer if a query fails
Browse files Browse the repository at this point in the history
This prevents issues with non-initialized pointers (issue #406)

(cherry picked from commit a268b1d)
  • Loading branch information
liviuchircu committed Apr 1, 2015
1 parent d17c201 commit 80ac9e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions db/db_query.c
Expand Up @@ -118,6 +118,8 @@ int db_do_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
error:
LM_ERR("error while preparing query\n");
err_exit:
if (_r)
*_r = NULL;
CON_OR_RESET(_h);
return -1;
}
Expand Down
18 changes: 15 additions & 3 deletions modules/db_mysql/dbase.c
Expand Up @@ -923,13 +923,25 @@ int db_mysql_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
int ret;

if (CON_HAS_PS(_h)) {
if (CON_HAS_UNINIT_PS(_h)||!has_stmt_ctx(_h,&(CON_MYSQL_PS(_h)->ctx))){
if (CON_HAS_UNINIT_PS(_h)||!has_stmt_ctx(_h,&(CON_MYSQL_PS(_h)->ctx))) {
ret = db_do_query(_h, _k, _op, _v, _c, _n, _nc, _o, NULL,
db_mysql_val2str, db_mysql_submit_dummy_query, NULL);
if (ret!=0) {CON_RESET_CURR_PS(_h);return ret;}
if (ret != 0) {
CON_RESET_CURR_PS(_h);
if (_r)
*_r = NULL;
return ret;
}
}

ret = db_mysql_do_prepared_query(_h, &query_holder, _v, _n, NULL, 0);
if (ret!=0) {CON_RESET_CURR_PS(_h);return ret;}
if (ret != 0) {
CON_RESET_CURR_PS(_h);
if (_r)
*_r = NULL;
return ret;
}

ret = db_mysql_store_result(_h, _r);
CON_RESET_CURR_PS(_h);
return ret;
Expand Down

0 comments on commit 80ac9e8

Please sign in to comment.