Skip to content

Commit

Permalink
strans/accept: fix cancel/rejection (#423)
Browse files Browse the repository at this point in the history
In sipsess_reply_2xx, the reply is sent using a server transaction which
sets the st to NULL when replying with scode >=200. This is problematic
when sending 2xx responses to PRACKs after which sess->st was NULL.
Now, st is not passed to sip_treplyf if the request was PRACK, so st is
not set to NULL.
  • Loading branch information
maximilianfridrich authored Jul 8, 2022
1 parent 3f725d5 commit a39ce9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/sipsess/accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ int sipsess_answer(struct sipsess *sess, uint16_t scode, const char *reason,
va_list ap;
int err;

if (!sess || (!sess->st
&& (sess->established || sess->awaiting_answer))
|| !sess->msg || scode < 200 || scode > 299)
if (!sess || !sess->st || !sess->msg || scode < 200 || scode > 299)
return EINVAL;

va_start(ap, fmt);
Expand Down
10 changes: 7 additions & 3 deletions src/sipsess/reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ int sipsess_reply_2xx(struct sipsess *sess, const struct sip_msg *msg,
{
struct sipsess_reply *reply;
struct sip_contact contact;
bool is_prack = false;
int err = ENOMEM;

reply = mem_zalloc(sizeof(*reply), destructor);
Expand All @@ -101,9 +102,10 @@ int sipsess_reply_2xx(struct sipsess *sess, const struct sip_msg *msg,
reply->msg = mem_ref((void *)msg);
reply->sess = sess;

is_prack = !pl_strcmp(&msg->met, "PRACK");
sip_contact_set(&contact, sess->cuser, &msg->dst, msg->tp);

err = sip_treplyf(&sess->st, &reply->mb, sess->sip,
err = sip_treplyf(is_prack ? NULL : &sess->st, &reply->mb, sess->sip,
msg, true, scode, reason,
"%H"
"%v"
Expand All @@ -123,7 +125,7 @@ int sipsess_reply_2xx(struct sipsess *sess, const struct sip_msg *msg,
if (err)
goto out;

if (pl_strcmp(&msg->met, "PRACK")) {
if (!is_prack) {
tmr_start(&reply->tmr, 64 * SIP_T1, tmr_handler, reply);
tmr_start(&reply->tmrg, SIP_T1, retransmit_handler, reply);
}
Expand All @@ -138,7 +140,9 @@ int sipsess_reply_2xx(struct sipsess *sess, const struct sip_msg *msg,

out:
if (err) {
sess->st = mem_deref(sess->st);
if (!is_prack)
sess->st = mem_deref(sess->st);

mem_deref(reply);
}

Expand Down

0 comments on commit a39ce9d

Please sign in to comment.