Skip to content

Commit

Permalink
acc: Fix prepared statements for the missed/acc tables
Browse files Browse the repository at this point in the history
Commit 4bc134f introduced a regression where the reused PS for the
"missed_calls" table (9 fields) would no longer match the PS for the
"acc" table (11 fields).  By reusing the former PS array, which is
shorter than required, the code would segfault.  Example scenario:

    * simple call from A -> B with:
        * do_accounting("db", "missed|failed")
        * call failure (e.g. 408 Request Timeout)
    * code crashes as soon as the "failed" acc entry is written

Many thanks to Nexphone for sponsoring this fix

(cherry picked from commit 5b86833)
  • Loading branch information
liviuchircu committed Nov 4, 2020
1 parent 229c5da commit 0fa6e7d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions modules/acc/acc.c
Expand Up @@ -511,12 +511,20 @@ void acc_db_close(void)
int acc_db_request( struct sip_msg *rq, struct sip_msg *rpl,
query_list_t **ins_list, int cdr_flag, int missed)
{
/**
* The list of people which have bugfixed these PS:
* d837ed865d - 2016, Bogdan. Fix crash.
* a250191728 - 2017, Razvan. Fix crash.
* latest - 2020, Liviu. Fix crash.
*/
static db_ps_t my_ps_ins = NULL;
static db_ps_t my_ps_ins2 = NULL;
static db_ps_t my_ps_ins3 = NULL;
static db_ps_t my_ps_ins4 = NULL;
static db_ps_t my_ps = NULL;
static db_ps_t my_ps2 = NULL;
static db_ps_t my_ps3 = NULL;
static db_ps_t my_ps4 = NULL;
db_ps_t *ps;
int m;
int n = 0;
Expand Down Expand Up @@ -578,10 +586,17 @@ int acc_db_request( struct sip_msg *rq, struct sip_msg *rpl,
else
ps = &my_ps2; /* CDR to custom table */
} else if (ctx) {
if (ins_list)
ps = &my_ps_ins; /* normal acc to known table */
else
ps = &my_ps; /* normal acc to custom table */
if (missed) {
if (ins_list)
ps = &my_ps_ins; /* normal acc to known missed table */
else
ps = &my_ps; /* normal acc to custom missed table */
} else {
if (ins_list)
ps = &my_ps_ins4; /* normal acc to known table */
else
ps = &my_ps4; /* normal acc to custom table */
}
} else {
/* no ctx - no extra */
if (ins_list)
Expand Down

0 comments on commit 0fa6e7d

Please sign in to comment.