Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions core/AmSipDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,18 @@ bool AmSipDialog::onRxReqSanity(const AmSipRequest& req)
+ int2str(get_random() % 10) + CRLF);
return false;
}

if (invite)
pending_invites++;
}

return rel100.onRequestIn(req);
// The 100rel check may reject the request with a stateless reply that does
// not pass through onReplyTxed(), so only count the INVITE as pending once
// it has been accepted; otherwise pending_invites would never drop back.
if (!rel100.onRequestIn(req))
return false;

if (invite)
pending_invites++;

return true;
}

bool AmSipDialog::onRxReqStatus(const AmSipRequest& req)
Expand Down
1 change: 1 addition & 0 deletions core/sip/parse_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ static int _parse_gen_params(list<sip_avp*>* params, const char** c,
DBG("'=' expected\n");
return MALFORMED_SIP_MSG;
}
break;

case VP_PNAME_EQU_SWS:
switch(**c){
Expand Down
8 changes: 5 additions & 3 deletions core/sip/parse_cseq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int parse_cseq(sip_cseq* cseq, const char* beg, int len)
case SP:
case HTAB:
cseq->method_str.set(beg,c-beg);
return 0;
goto method;
}
break;

Expand All @@ -117,8 +117,8 @@ int parse_cseq(sip_cseq* cseq, const char* beg, int len)
cseq->num_str.set(beg,c-(st==ST_CRLF?2:1)-beg);
break;
case C_METHOD:
cseq->method_str.set(beg,c-beg);
return 0;
cseq->method_str.set(beg,c-(st==ST_CRLF?2:1)-beg);
goto method;
}
st = saved_st;
break;
Expand All @@ -130,6 +130,8 @@ int parse_cseq(sip_cseq* cseq, const char* beg, int len)
}

cseq->method_str.set(beg,c-beg);

method:
if(parse_method(&cseq->method, cseq->method_str.s, cseq->method_str.len) < 0){

DBG("Cseq method parsing failed\n");
Expand Down
3 changes: 2 additions & 1 deletion core/sip/parse_cseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ struct sip_cseq: public sip_parsed_hdr

sip_cseq()
: sip_parsed_hdr(),
num(0)
num(0),
method(0)
{}
};

Expand Down
1 change: 1 addition & 0 deletions core/sip/trans_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ int _trans_layer::send_sf_error_reply(const trans_ticket* tt, const sip_msg* req
cstring to_tag(to_tag_buf,SL_TOTAG_LEN);

sip_msg reply;
reply.type = SIP_REPLY;
reply.u.reply = new sip_reply(reply_code,reason);

char* c = (char*)hdrs.s;
Expand Down
7 changes: 7 additions & 0 deletions core/sip/trans_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ sip_trans* trans_bucket::match_1xx_prack(sip_msg* msg)
}
sip_trans* t = *it;

// RFC 3262: only provisional replies to an INVITE are sent
// reliably, so a PRACK can only match an INVITE server transaction.
if( (t->type != TT_UAS) ||
(t->msg->u.request->method != sip_request::INVITE) ){
continue;
}

/* first, check quickly if lenghts match (From tag, To tag, Call-ID) */

sip_from_to* from = dynamic_cast<sip_from_to*>(msg->from->p);
Expand Down
39 changes: 39 additions & 0 deletions core/tests/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,45 @@ FCTMF_SUITE_BGN(test_parser) {
}
FCT_TEST_END();

// A method followed by whitespace used to return before the method was
// parsed, leaving sip_cseq::method uninitialised (issue #655).
FCT_TEST_BGN(cseq_method_trailing_whitespace) {
const char *values[] = {"1 INVITE ", "1 INVITE\t", "1 INVITE \r\n", "1 INVITE\r\n "};
for (size_t i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
sip_cseq cseq;
cseq.method = -1;
int rc = parse_cseq(&cseq, values[i], strlen(values[i]));
fct_xchk(rc == 0 && cseq.method == sip_request::INVITE && cseq.method_str.len == 6,
"CSeq '%s': rc=%d method=%d method_len=%d", values[i], rc, cseq.method, cseq.method_str.len);
}
}
FCT_TEST_END();

FCT_TEST_BGN(cseq_method_is_initialised) {
sip_cseq cseq;
fct_chk_eq_int(cseq.method, sip_request::OTHER_METHOD);
}
FCT_TEST_END();

// Whitespace between a parameter name and '=' used to fall through into
// the value state, so "tag = abc" got the value "= abc" (issue #655).
FCT_TEST_BGN(gen_params_whitespace_before_equals) {
const char *value = "tag = abc;branch =z9hG4bK776";
const char *c = value;
list<sip_avp *> params;
int rc = parse_gen_params(&params, &c, strlen(value), '\0');
fct_req(rc == 0);
fct_req(params.size() == 2);
sip_avp *tag = params.front();
sip_avp *branch = params.back();
fct_chk(string(tag->name.s, tag->name.len) == "tag");
fct_chk(string(tag->value.s, tag->value.len) == "abc");
fct_chk(string(branch->name.s, branch->name.len) == "branch");
fct_chk(string(branch->value.s, branch->value.len) == "z9hG4bK776");
free_gen_params(&params);
}
FCT_TEST_END();

// The CSeq number has to fit in 32 bits (RFC 3261 section 8.1.1.5); a
// larger one must not wrap into a different, valid looking number.

Expand Down
Loading