Skip to content

Commit

Permalink
mid_registrar: Fix regression introduced in c11f926
Browse files Browse the repository at this point in the history
Avoid re-using anonymous structures outside of the block scope they were
declared in, as the compiler may easily re-use that stack memory outside
the given scope.

Credits to Andrew Yager for providing debugging info, as well as
bisecting down to the exact culprit commit!

(cherry picked from commit 8df8fd9)
  • Loading branch information
liviuchircu committed Sep 28, 2021
1 parent 4e1bb9c commit 6765b7d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/mid_registrar/save.c
Expand Up @@ -1290,6 +1290,7 @@ static inline int save_restore_rpl_contacts(struct sip_msg *req,
int tcp_check = 0;
struct sip_uri uri;
struct ct_mapping *ctmap;
struct mr_ct_data ct_data;
struct hdr_field *hdr;
struct list_head *_;

Expand Down Expand Up @@ -1389,10 +1390,11 @@ static inline int save_restore_rpl_contacts(struct sip_msg *req,
if (reg_mode == MID_REG_THROTTLE_CT) {
/* populate extra ct stuff between "insert" and "replicate" */
ci->pre_replicate_cb = mid_reg_store_ct_data;
ci->pre_replicate_info = &(struct mr_ct_data){
memcpy(&ct_data, &(struct mr_ct_data){
mri, &_c->uri, ctmap->expires, e_out,
get_act_time(), ci->cseq
};
}, sizeof ct_data);
ci->pre_replicate_info = &ct_data;
}

LM_DBG("INSERTING contact with expires %lu\n", ci->expires);
Expand Down Expand Up @@ -1533,6 +1535,7 @@ static inline int save_restore_req_contacts(struct sip_msg *req,
struct sip_uri uri;
struct list_head *_;
struct ct_mapping *ctmap;
struct mr_ct_data ct_data;

if (str2int(&get_cseq(rpl)->number, &cseq) < 0) {
rerrno = R_INV_CSEQ;
Expand Down Expand Up @@ -1653,10 +1656,11 @@ static inline int save_restore_req_contacts(struct sip_msg *req,
if (reg_mode == MID_REG_THROTTLE_AOR) {
/* populate extra ct stuff between "insert" and "replicate" */
ci->pre_replicate_cb = mid_reg_store_ct_data;
ci->pre_replicate_info = &(struct mr_ct_data){
memcpy(&ct_data, &(struct mr_ct_data){
mri, &_c->uri, ctmap->expires, e_out,
mri->last_reg_ts, ci->cseq
};
}, sizeof ct_data);
ci->pre_replicate_info = &ct_data;
}

LM_DBG("INSERTING contact with expires %lu\n", ci->expires);
Expand Down

0 comments on commit 6765b7d

Please sign in to comment.