diff options
author | twilson <twilson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-11-19 22:06:10 +0000 |
---|---|---|
committer | twilson <twilson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-11-19 22:06:10 +0000 |
commit | de099b6b1042537fe84444add7bbe28f07b4be3b (patch) | |
tree | 51438e06e34b823fd2c2f0556ed94b35659cd477 | |
parent | bd89799c07d99b3a9078ee1debf9e8a6017d26ee (diff) |
Merged revisions 295672 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2
................
r295672 | twilson | 2010-11-19 13:55:48 -0800 (Fri, 19 Nov 2010) | 15 lines
Merged revisions 295628 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r295628 | twilson | 2010-11-19 12:53:36 -0800 (Fri, 19 Nov 2010) | 8 lines
Discard responses with more than one Via
This is not a perfect solution as headers that are joined via commas are not
detected. This is a parsing issue that to fix "correctly" would necessitate
a new SIP parser.
Review: https://reviewboard.asterisk.org/r/1019/
........
................
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.8@295673 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | channels/chan_sip.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 774d70181..7f9e9bc33 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -23479,6 +23479,9 @@ static int handle_incoming(struct sip_pvt *p, struct sip_request *req, struct as const char *cmd; const char *cseq; const char *useragent; + const char *via; + const char *callid; + int via_pos = 0; int seqno; int len; int respid; @@ -23489,13 +23492,19 @@ static int handle_incoming(struct sip_pvt *p, struct sip_request *req, struct as int oldmethod = p->method; int acked = 0; - /* Get Method and Cseq */ + /* RFC 3261 - 8.1.1 A valid SIP request must contain To, From, CSeq, Call-ID and Via. + * 8.2.6.2 Response must have To, From, Call-ID CSeq, and Via related to the request, + * so we can check to make sure these fields exist for all requests and responses */ cseq = get_header(req, "Cseq"); cmd = REQ_OFFSET_TO_STR(req, header[0]); + /* Save the via_pos so we can check later that responses only have 1 Via header */ + via = __get_header(req, "Via", &via_pos); + /* This must exist already because we've called find_call by now */ + callid = get_header(req, "Call-ID"); /* Must have Cseq */ - if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq)) { - ast_log(LOG_ERROR, "Missing Cseq. Dropping this SIP message, it's incomplete.\n"); + if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq) || ast_strlen_zero(via)) { + ast_log(LOG_ERROR, "Dropping this SIP message with Call-ID '%s', it's incomplete.\n", callid); error = 1; } if (!error && sscanf(cseq, "%30d%n", &seqno, &len) != 1) { @@ -23537,6 +23546,13 @@ static int handle_incoming(struct sip_pvt *p, struct sip_request *req, struct as ast_log(LOG_WARNING, "Invalid SIP response code: '%d'\n", respid); return 0; } + /* RFC 3261 - 8.1.3.3 If more than one Via header field value is present in a reponse + * the UAC SHOULD discard the message. This is not perfect, as it will not catch multiple + * headers joined with a comma. Fixing that would pretty much involve writing a new parser */ + if (!ast_strlen_zero(__get_header(req, "via", &via_pos))) { + ast_log(LOG_WARNING, "Misrouted SIP response '%s' with Call-ID '%s', too many vias\n", e, callid); + return 0; + } if (p->ocseq && (p->ocseq < seqno)) { ast_debug(1, "Ignoring out of order response %d (expecting %d)\n", seqno, p->ocseq); return -1; |