Skip to content

[BUG] error_route not triggered for parsing error on first line of SIP message #2533

@markallen01666

Description

@markallen01666

This is either a bug or a feature request:

We were seeing an issue with a corrupted SIP message (example below). To handle it we wanted to use error_route triggered by the parsing error, but because the error was with the first line of the message, error_route was not activated.

From https://github.com/OpenSIPS/opensips/blob/master/receive.c#L145 etc, it appears that this is a deliberate decision. The code reads:

if (parse_msg(in_buff.s,len, msg)!=0){
tmp=ip_addr2a(&(rcv_info->src_ip));
LM_ERR("Unable to parse msg received from [%s:%d]\n", tmp, rcv_info->src_port); /* if a REQUEST msg was detected (first line was successfully parsed) we should trigger the error route */
if ( msg->first_line.type==SIP_REQUEST && sroutes->error.a!=NULL ) {
if (existing_context == NULL) prepare_context( ctx, parse_error );
current_processing_ctx = ctx;
run_error_route(msg, 1);
}
goto parse_error;
}

However, this contradicts the documentation (https://www.opensips.org/Documentation/Script-Routes-3-1#toc5) which reads...

The error route is executed automatically when a parsing error occurs during SIP request processing

...there is no mention that if the error is with parsing the first line of the SIP message, error_route doesn't activate.

To resolve this I think that there are three possible solutions:

  • The test for first line being SIP should be removed (could the user choose to test for a non-SIP message using sipmsg_validate()?)
  • A parameter could be added to allow the coder to turn on triggering of error_route on failure of parsing the first line if they choose to
  • It could be left as it is, but documentation updated to make it clear that it doesn't work if the first line is corrupted

Here's an example. What we are seeing is this message which starts with part of a previous SIP message (due to dialer error I believe)...

Contact: <sip:1234 at abc.def.com:5060>
User-Agent: MWWRTC 3.4.21042
Accept: application/sdp,application/dtmf-relay,text/plain

...preceding...

SIP/2.0 200 OK
Via: SIP/2.0/TCP 192.168.1.23:5060;received=192.168.1.23;rport=42385;branch=z9hG4bK22a8.4fa6d127.0;i=b4986fe4
...etc...

...so OpenSIPS is failing to parse the message (the colon at the end of 'Contact:' seems to be the thing that breaks it).

My list post about this - http://lists.opensips.org/pipermail/users/2021-May/044779.html
Previous report of this issue - https://opensips.org/pipermail/users/2019-February/040605.html

Relevant log entries:

ERROR:core:parse_method: invalid character :
DBG:core:tcp_read_req: tcp_read_req end
INFO:core:parse_first_line: failed to parse the method
INFO:core:parse_first_line: bad message
DBG:core:parse_msg: invalid message
ERROR:core:parse_msg: message=<Contact:
<sip:1234 at abc.def.com:5060>#15#012User-Agent:
MWWRTC 3.4.21042#015#012Accept:
application/sdp,application/dtmf-relay,text/plain#015#012SIP/2.0 200
OK#015#012Via: SIP/2.0/TCP
192.168.1.23:5060;received=192.168.1.23;rport=42385;branch=z9hG4bK22a8.4fa6d127.0;i=b4986fe4#015#012Via:
SIP/2.0/WSS
98kaag0xmybq.invalid;received=4.56.78.110;branch=z9hG4bKU6O3fJQGeLvuACMTXTArJgJW73rOD5dU;rport=52570#015#012From:
<sip:1234 at abc.def.com>;tag=Lyk010G476K7xcKrE84M#015#012To: <
sip:1234 at abc.def.com>;tag=af78-6213d386c3edcd02707b0c0aa8423d3a#015#012Call-ID:
666b5e7c-cef3-f306-4b79-60d3160dc5d0#015#012CSeq: 28825
REGISTER#015#012Contact: <sips:1234 at 98kaag0xmybq.invalid
;transport=wss>;expires=60;received="sip:4.56.78.110:52570"#15#012Server:
OpenSIPS (3.1.1 (x86_64/linux))#15#012Content-Length: 0#015#012#015#012>
ERROR:core:receive_msg: Unable to parse msg received from [192.168.1.23:5060
]
ERROR:core:tcp_handle_req: receive_msg failed

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions