Discussion:
[sr-dev] [kamailio/kamailio] filter_body() fails when there isn't a space after "Content-Type:" (#2748)
duarterocha91
2021-05-27 11:17:44 UTC
Permalink
I've made some testing and found that filter_body() fails when body is something like "Content-Type:application\/sdp\r\n\r\n".

If i use this correction to add a space the filter works correctly :

replace_body_all("Content-Type:application\/sdp\r\n\r\n","Content-Type: application/sdp\r\n\r\n");

#Makes the changes to the message persistent, returns 1 if sucessful, 0 if it fails
if(msg_apply_changes())
{
xnotice("Kamailio_Log : reply_route : Changes to message applied");
}

I looked into the textops.c and found this line which i think might be the problem :

while (find_line_start("Content-Type: ", 14, &start, &len))

If more info is needed please let me know.

Cheers
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748
Daniel-Constantin Mierla
2021-05-31 08:47:56 UTC
Permalink
Thanks for report and analysis. Can you try with master branch or the patch referenced above?

If fixes it, then I will backport.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-851329411
duarterocha91
2021-05-31 14:18:52 UTC
Permalink
Hi Daniel,

Thanks for the update.

I'm using kamailio 5.4 and i've copied the textops files from the link you provided and replaced the textops files. Made make clean and make all on the textops folder and got these warnings :

"[***@dev_sbc_a_vts01 textops]# make
CC (gcc) [M textops.so] textops.o
textops.c: In function ‘find_hdr_line_start’:
textops.c:1614:2: warning: implicit declaration of function ‘parse_hname2_str’ [-Wimplicit-function-declaration]
if(parse_hname2_str(&sname, &h1)==NULL) {
^
textops.c:1614:34: warning: comparison between pointer and integer [enabled by default]
if(parse_hname2_str(&sname, &h1)==NULL) {
^
textops.c: In function ‘ki_remove_hf_idx’:
textops.c:1815:34: warning: comparison between pointer and integer [enabled by default]
if(parse_hname2_str(hname, &hfm)==NULL) {
^
textops.c: In function ‘ki_str_ifind’:
textops.c:4457:2: warning: implicit declaration of function ‘str_casesearch’ [-Wimplicit-function-declaration]
p = str_casesearch(txt, needle);
^
textops.c:4457:4: warning: assignment makes pointer from integer without a cast [enabled by default]
p = str_casesearch(txt, needle);
^
CC (gcc) [M textops.so] api.o
CC (gcc) [M textops.so] txt_var.o
LD (gcc) [M textops.so] textops.so
"

After that i've done the make all; make install . When restarting Kamailio i receive this error loading the module :

" ERROR: <core> [core/sr_module.c:512]: load_module(): could not open module </usr/local/kamailio-5.4/lib64/kamailio/modules/textops.so>: /usr/local/kamailio-5.4/lib64/kamailio/modules/textops"

Is only replacing the module enough or do i need to install the complete version?

Best Regards,


--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-851522028
Daniel-Constantin Mierla
2021-05-31 15:12:22 UTC
Permalink
You need to backport functions from the core, the best is to try with master and see if works, then I can backport easily to 5.5. To older release series it may require more work to backport, first is better to confirm if works.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-851551603
duarterocha91
2021-06-01 13:57:11 UTC
Permalink
Hi Daniel,

Sorry for taking too long. I've tried the same scenario with master and with 5.4.1.

5.4.1 has the behaviour described previously.

On master i got some parsing errors on the packet when invoking filter_body("application/sdp") on a multipart body. I've attached a picture with the errors logged. If you want i can send you to packet too.

Cheers
![Captura_Falha_Filtro](Loading Image...)
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-852146582
Daniel-Constantin Mierla
2021-06-02 15:07:16 UTC
Permalink
Can you copy&paste the logs, screenshots are not troubleshooting friendly with only text content? Then it is easy to copy it and search to see where in the code the logs are printed from. Size is also smaller, being friendlier for mobile connections.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-853107607
duarterocha91
2021-06-02 15:29:03 UTC
Permalink
Sorry.

This is my code for filtering :

"request_route {

xerr("Before filter_body");
if (filter_body("application/sdp")) { xerr("Filtered with sucess"); }
else { xerr("Filtering failed");}
"

The log is the following :

"2021-06-02T16:13:53.396443+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <script>: Before filter_body
2021-06-02T16:13:53.396677+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound]
2021-06-02T16:13:53.396886+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [pplication/sdp]
2021-06-02T16:13:53.397141+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012v=0#015#012o=- 184]
2021-06-02T16:13:53.397337+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [v=0#015#012o=- 18454]
2021-06-02T16:13:53.397527+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [o=- 1845407145]
2021-06-02T16:13:53.397716+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [s=-#015#012c=IN IP4 ]
2021-06-02T16:13:53.397914+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [c=IN IP4 212.1]
2021-06-02T16:13:53.398154+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [t=0 0#015#012m=audio]
2021-06-02T16:13:53.398346+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [m=audio 22138 ]
2021-06-02T16:13:53.398548+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [a=rtpmap:101 t]
2021-06-02T16:13:53.398813+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [a=rtpmap:96 CL]
2021-06-02T16:13:53.399037+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012--unique-bou]
2021-06-02T16:13:53.399230+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound]
2021-06-02T16:13:53.399428+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [pplication/ISU]
2021-06-02T16:13:53.399621+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [Content-Dispos]
2021-06-02T16:13:53.399815+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012#001]
2021-06-02T16:13:53.400028+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#001]
2021-06-02T16:13:53.400234+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound]
2021-06-02T16:13:53.400427+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <script>: Filtering failed
"


I've also attached the packet body :



"Message Body
MIME Multipart Media Encapsulation, Type: multipart/mixed, Boundary: "unique-boundary-1"
[Type: multipart/mixed]
First boundary: --unique-boundary-1\r\n
Encapsulated multipart part: (application/sdp)
Content-Type:application/sdp\r\n\r\n
Session Description Protocol
Session Description Protocol Version (v): 0
Owner/Creator, Session Id (o): - 1845407145 1 IN IP4 1.1.1.1
Session Name (s): -
Connection Information (c): IN IP4 1.1.1.1
Time Description, active time (t): 0 0
Media Description, name and address (m): audio 22138 RTP/AVP 8 0 18 3 13 101 96
Media Attribute (a): rtpmap:101 telephone-event/8000
Media Attribute (a): rtpmap:96 CLEARMODE/8000
Boundary: \r\n--unique-boundary-1\r\n
Encapsulated multipart part: (application/isup)
Content-Type:application/ISUP;base=itu-t92+;version=itu-t\r\n
Content-Disposition:signal;handling=required\r\n\r\n
ISDN User Part
Message Type: Initial address (1)
Nature of Connection Indicators : 0x0
Forward Call Indicators : 0x6001
Calling Party's category : 0xa (ordinary calling subscriber)
Transmission medium requirement : 0 (speech)
Called Party NumberCalled Party Number: 222222222
Pointer to start of optional part: 10
Parameter: (t=10, l=8) Calling party number: Calling party numberCalling Party Number: 333333333
Parameter: (t=192, l=9) Generic number: Generic numberGeneric Number: 333333333
End of optional parameters (0)
Last boundary: \r\n--unique-boundary-1--\r\n"


If more info or testing is needed please let me know.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-853125172
Daniel-Constantin Mierla
2021-06-02 16:13:23 UTC
Permalink
Can you try again with master branch version? I pushed two more commits.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-853160564
duarterocha91
2021-06-02 17:44:28 UTC
Permalink
I've tried with the new code and i get the same errors in the log :

2021-06-02T18:43:29.662320+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <script>: Before filter_body
2021-06-02T18:43:29.662548+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound]
2021-06-02T18:43:29.662733+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [pplication/sdp]
2021-06-02T18:43:29.662922+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012v=0#015#012o=- 184]
2021-06-02T18:43:29.663170+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [v=0#015#012o=- 18455]
2021-06-02T18:43:29.663358+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [o=- 1845520355]
2021-06-02T18:43:29.663535+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [s=-#015#012c=IN IP4 ]
2021-06-02T18:43:29.663709+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [c=IN IP4 212.1]
2021-06-02T18:43:29.663924+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [t=0 0#015#012m=audio]
2021-06-02T18:43:29.664153+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [m=audio 26376 ]
2021-06-02T18:43:29.664333+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [a=rtpmap:101 t]
2021-06-02T18:43:29.664538+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [a=rtpmap:96 CL]
2021-06-02T18:43:29.664718+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012--unique-bou]
2021-06-02T18:43:29.664897+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound]
2021-06-02T18:43:29.665119+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [pplication/ISU]
2021-06-02T18:43:29.665323+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [Content-Dispos]
2021-06-02T18:43:29.665607+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012#001]
2021-06-02T18:43:29.665864+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#001]
2021-06-02T18:43:29.666135+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound]
2021-06-02T18:43:29.666341+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <script>: Filtering failed
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-853252904
Daniel-Constantin Mierla
2021-06-02 19:18:49 UTC
Permalink
Can you give the output for:

```
/usr/local/kamailio-5.4/sbin/kamailio -v
```

Did you backport patches or run master branch?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-853320134
duarterocha91
2021-06-07 10:35:43 UTC
Permalink
For the previous test i downloaded and installed the master branch. For this one i only downloaded the core and re-installed.

Should i do a fresh install?

kamailio -v output is the following :

version: kamailio 5.6.0-dev0 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-855813663
Daniel-Constantin Mierla
2021-06-07 11:04:05 UTC
Permalink
Yes, do a fresh install of everything from git master branch.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2748#issuecomment-855830540
Continue reading on narkive:
Loading...