Skip to content

Commit

Permalink
sql_cacher: Fix invalid memory access
Browse files Browse the repository at this point in the history
Similar to commit a223c82.  Avoid returning a pointer to a freed pkg
memory area.

(cherry picked from commit 313a343)
  • Loading branch information
liviuchircu committed Sep 17, 2018
1 parent 9ad56bc commit d8e37cb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/sql_cacher/sql_cacher.c
Expand Up @@ -1378,7 +1378,7 @@ static void unlink_from_query_list(struct queried_key *pos)
}

/* return:
* 0 - succes
* 0 - succes => if str column, @str_res->s must be pkg_free()'d
* 1 - succes, null value in db
* -1 - error
* -2 - not found in sql db
Expand Down Expand Up @@ -1458,6 +1458,15 @@ static int on_demand_load(pv_name_fix_t *pv_name, str *str_res, int *int_res,
if (pv_name->last_str == -1)
optimize_cdb_decode(pv_name);
rc = cdb_val_decode(pv_name, &cdb_res, rld_vers_retry, str_res, int_res);
if (is_str_column(pv_name) && rc == 0) {
if (pkg_str_dup(&st, str_res) != 0) {
LM_ERR("oom\n");
rc = -1;
memset(str_res, 0, sizeof *str_res);
} else {
*str_res = st;
}
}

pkg_free(cdb_res.s);

Expand Down

0 comments on commit d8e37cb

Please sign in to comment.