Skip to content

Commit

Permalink
fix issue when sip uri has a question mark in the user part of sip uri (
Browse files Browse the repository at this point in the history
#314)

* fix issue when sip uri has a question mark in the user part of sip uri

* add test case
  • Loading branch information
davehorton authored Nov 6, 2023
1 parent 2c397d3 commit 695b370
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/drachtio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ namespace drachtio {
// no go: if we can't decode it then we have an invalid input
return false ;
}
if( nullptr == url->url_user && std::string::npos != uri.find("@")) {
DR_LOG(log_info) << "normalizeSipUri: invalid uri, user part contains invalid chars:" << uri ;
return false;
}

/* we allow applications to just give us a phone number sometimes, and that ends up parsed into the host portion with no scheme */
if( NULL == url->url_scheme && NULL == url->url_user && NULL != url->url_host ) {
Expand Down
99 changes: 99 additions & 0 deletions test/scenarios/uac-invalid-uri-user.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<!-- This program is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU General Public License as -->
<!-- published by the Free Software Foundation; either version 2 of the -->
<!-- License, or (at your option) any later version. -->
<!-- -->
<!-- This program is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!-- GNU General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with this program; if not, write to the -->
<!-- Free Software Foundation, Inc., -->
<!-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Sipp default 'uac' scenario. -->
<!-- -->

<scenario name="Basic Sipstone UAC">
<!-- In client mode (sipp placing calls), the Call-ID MUST be -->
<!-- generated by sipp. To do so, use [call_id] keyword. -->
<send retrans="500">
<![CDATA[
INVITE sip:-TXDOTFILE-FILEREVIEWCOV-INSINT%26FIRST60DAYS-SENTAOT-1STATTEMPTMADE-DCSDL-R/SREGOWNER-REVIEWISO%26LPR%26CARFAX-PR-R/SREGOWNER/DRIVERONFILE-RS/NIONFILE-IVRECOVER-IASENT-INSINTCOVREVSENT***PEND-INSINTCOV-AOT-EST-PAYORDENY?-CLOSE@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
Max-Forwards: 69
To: <sip:-TXDOTFILE-FILEREVIEWCOV-INSINT%26FIRST60DAYS-SENTAOT-1STATTEMPTMADE-DCSDL-R/SREGOWNER-REVIEWISO%26LPR%26CARFAX-PR-R/SREGOWNER/DRIVERONFILE-RS/NIONFILE-IVRECOVER-IASENT-INSINTCOVREVSENT***PEND-INSINTCOV-AOT-EST-PAYORDENY?-CLOSE@[remote_ip]:[remote_port]>
From: <sip:[email protected]>;tag=c11ralrakt
Call-ID: [call_id]
CSeq: 1 INVITE
X-Nextiva-One-Session: lax4.int.voipdnsservers.com
X-Nextiva-Corp-Acct-Number: 3681069
X-Nextiva-User-UUID: 904baa30-d2db-11eb-a8c8-005056a33d5a
Allow-Events: conference,talk,hold
Contact: <sip:[email protected];transport=ws;ob>
Session-Expires: 90;refresher=uac
Allow: INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY
Supported: timer,ice,replaces,outbound
User-Agent: JsSIP/3.20.0 DesktopApp/1.15.2 NextivaBrowserSoftphone/5.29.2
Content-Type: application/sdp
Content-Length: [len]
v=0
o=- 2868383482636261453 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0 1
a=extmap-allow-mixed
a=msid-semantic: WMS 8feaf12e-f910-403c-b695-21f9d52358c5
m=audio 29982 UDP/TLS/RTP/SAVPF 111 63 103 9 0 8 105 13 110 113 126
c=IN IP4 165.22.12.254
]]>
</send>

<recv response="100"
optional="true">
</recv>

<recv response="180" optional="true">
</recv>

<recv response="183" optional="true">
</recv>

<!-- By adding rrs="true" (Record Route Sets), the route sets -->
<!-- are saved and used for following messages sent. Useful to test -->
<!-- against stateful SIP proxies/B2BUAs. -->
<recv response="500" rtd="true" rrs="true">
</recv>

<!-- Packet lost can be simulated in any send/recv message by -->
<!-- by adding the 'lost = "10"'. Value can be [1-100] percent. -->
<send>
<![CDATA[
ACK [next_url] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: [service] <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 1 ACK
[routes]
Max-Forwards: 70
Content-Length: 0
]]>
</send>

<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>

<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>

</scenario>
116 changes: 116 additions & 0 deletions test/scenarios/uac-long-uri.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<!-- This program is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU General Public License as -->
<!-- published by the Free Software Foundation; either version 2 of the -->
<!-- License, or (at your option) any later version. -->
<!-- -->
<!-- This program is distributed in the hope that it will be useful, -->
<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
<!-- GNU General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU General Public License -->
<!-- along with this program; if not, write to the -->
<!-- Free Software Foundation, Inc., -->
<!-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Sipp default 'uac' scenario. -->
<!-- -->

<scenario name="Basic Sipstone UAC">
<!-- In client mode (sipp placing calls), the Call-ID MUST be -->
<!-- generated by sipp. To do so, use [call_id] keyword. -->
<send retrans="500">
<![CDATA[
INVITE sip:901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: <sip:901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068901262806890126280689012628068@[remote_ip]:[remote_port]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: <sip:sipp@[local_ip]:[local_port]>
Max-Forwards: 70
Subject: very long sdp
Content-Type: application/sdp
Content-Length: [len]
v=0
o=- 2868383482636261453 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0 1
a=extmap-allow-mixed
a=msid-semantic: WMS 8feaf12e-f910-403c-b695-21f9d52358c5
m=audio 29982 UDP/TLS/RTP/SAVPF 111 63 103 9 0 8 105 13 110 113 126
c=IN IP4 165.22.12.254
]]>
</send>

<recv response="100"
optional="true">
</recv>

<recv response="180" optional="true">
</recv>

<recv response="183" optional="true">
</recv>

<!-- By adding rrs="true" (Record Route Sets), the route sets -->
<!-- are saved and used for following messages sent. Useful to test -->
<!-- against stateful SIP proxies/B2BUAs. -->
<recv response="200" rtd="true" rrs="true">
</recv>

<!-- Packet lost can be simulated in any send/recv message by -->
<!-- by adding the 'lost = "10"'. Value can be [1-100] percent. -->
<send>
<![CDATA[
ACK [next_url] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: [service] <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 1 ACK
[routes]
Max-Forwards: 70
Content-Length: 0
]]>
</send>

<!-- This delay can be customized by the -d command-line option -->
<!-- or by adding a 'milliseconds = "value"' option here. -->
<pause/>

<!-- The 'crlf' option inserts a blank line in the statistics report. -->
<send retrans="500">
<![CDATA[
BYE [next_url] SIP/2.0
Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[pid]SIPpTag00[call_number]
To: [service] <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
Call-ID: [call_id]
CSeq: 2 BYE
[routes]
Max-Forwards: 70
Content-Length: 0
]]>
</send>

<recv response="200" crlf="true">
</recv>

<!-- definition of the response time repartition table (unit is ms) -->
<ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>

<!-- definition of the call length repartition table (unit is ms) -->
<CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>

</scenario>
6 changes: 6 additions & 0 deletions test/test-fixtures-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"uac": {"name": "uac-long-sdp.xml", "target": "127.0.0.1:5090"},
"message": "b2b: handles very long sdp"
},
{
"server": {"config": "drachtio.conf.xml", "args": ["--memory-debug"]},
"script": {"name": "uas", "function": "b2b"},
"uac": {"name": "uac-invalid-uri-user.xml", "target": "127.0.0.1:5090"},
"message": "b2b: rejects invalid uri user part"
},
{
"server": {"config": "drachtio.conf.xml", "args": ["--memory-debug"]},
"script": {"name": "uas", "function": "b2b"},
Expand Down
8 changes: 8 additions & 0 deletions test/test-fixtures-uac-invalid-uri-user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"server": {"config": "drachtio.conf.xml", "args": ["--memory-debug"]},
"script": {"name": "uas", "function": "b2b"},
"uac": {"name": "uac-invalid-uri-user.xml", "target": "127.0.0.1:5090"},
"message": "b2b: rejects invalid uri user part"
}
]
9 changes: 9 additions & 0 deletions test/test-fixtures-uac-long-uri.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"server": {"config": "drachtio.conf.xml", "args": ["--memory-debug"]},
"script": {"name": "uas", "function": "b2b"},
"uas": {"name": "uas-success.xml", "port": 5094, "transport": "tcp"},
"uac": {"name": "uac-long-uri.xml", "target": "127.0.0.1:5090"},
"message": "b2b: handles very long uri"
}
]

0 comments on commit 695b370

Please sign in to comment.