Skip to content

Commit

Permalink
dialog: parse contact in separate structure
Browse files Browse the repository at this point in the history
This avoids concurrent access to the contact header's parsed structure
in request messages saved in shm - addresses ticket #2095

(cherry picked from commit df68e3b)
  • Loading branch information
razvancrainea committed Aug 26, 2020
1 parent a5ecdfe commit 4ec1d26
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions modules/dialog/dlg_handlers.c
Expand Up @@ -54,6 +54,7 @@
#include "../../data_lump.h"
#include "../../parser/parse_to.h"
#include "../../parser/parse_cseq.h"
#include "../../parser/contact/contact.h"
#include "../../parser/contact/parse_contact.h"
#include "../../parser/parse_rr.h"
#include "../../parser/parse_cseq.h"
Expand Down Expand Up @@ -1258,16 +1259,26 @@ static inline int dlg_update_contact(struct dlg_cell *dlg, struct sip_msg *msg,
{
str contact, contact_hdr;
char *tmp;
int ret = 0;
contact_t *ct = NULL;

if (!msg->contact &&
(parse_headers(msg, HDR_CONTACT_F, 0) < 0 || !msg->contact)) {
LM_DBG("INVITE or UPDATE without a contact - not updating!\n");
return 0;
} else if (!msg->contact->parsed && parse_contact(msg->contact) < 0) {
LM_INFO("INVITE or UPDATE with broken contact - not updating!\n");
return 0;
}
contact = ((contact_body_t *)msg->contact->parsed)->contacts->uri;
if (!msg->contact->parsed) {
contact = msg->contact->body;
trim_leading(&contact);
if (parse_contacts(&contact, &ct) < 0) {
LM_INFO("INVITE or UPDATE with broken contact - not updating!\n");
return 0;
}
contact = ct->uri;
LM_INFO("DBG: Found unparsed contact [%.*s]\n", contact.len, contact.s);
} else {
contact = ((contact_body_t *)msg->contact->parsed)->contacts->uri;
}
contact_hdr.s = msg->contact->name.s;
contact_hdr.len = msg->contact->len;

Expand All @@ -1283,7 +1294,7 @@ static inline int dlg_update_contact(struct dlg_cell *dlg, struct sip_msg *msg,
strncmp(dlg->legs[leg].contact.s, contact.s, contact.len) == 0) {
LM_DBG("Using the same contact <%.*s> for dialog %p on leg %d\n",
contact.len, contact.s, dlg, leg);
return 0;
goto end;
}
dlg->flags |= DLG_FLAG_CHANGED;
LM_DBG("Replacing old contact <%.*s> for dialog %p on leg %d\n",
Expand All @@ -1293,14 +1304,18 @@ static inline int dlg_update_contact(struct dlg_cell *dlg, struct sip_msg *msg,
tmp = shm_malloc(contact.len);
if (!tmp) {
LM_ERR("not enough memory for new contact!\n");
return -1;
ret = -1;
goto end;
}
dlg->legs[leg].contact.s = tmp;
dlg->legs[leg].contact.len = contact.len;
memcpy(dlg->legs[leg].contact.s, contact.s, contact.len);
LM_DBG("Updated contact to <%.*s> for dialog %p on leg %d\n",
contact.len, contact.s, dlg, leg);
return 1;
ret = 1;
end:
if (ct) free_contacts(&ct);
return ret;
}


Expand Down

0 comments on commit 4ec1d26

Please sign in to comment.