|
From: | Aymeric Moizard |
Subject: | Re: [osip-dev] Issue with osip_message_parse |
Date: | Mon, 2 Feb 2015 21:14:10 +0100 |
Hi Again,In the early days, osip wasn't supporting binary attachement and was focusingon application/sdp. For a long time, binary attachement are supported, but thecurrent code does't accept attachement without content-length (so UDP) except ifthe content-type is application/sdp.Because we have full size of packet today, this restriction doesn't look necessaryany more and we can accept any content-type when content-legnth is missing.diff --git a/src/osipparser2/osip_message_parse.c b/src/osipparser2/osip_message_parse.cindex e305cf0..28c6411 100644--- a/src/osipparser2/osip_message_parse.c+++ b/src/osipparser2/osip_message_parse.c@@ -706,19 +706,11 @@ msg_osip_body_parse (osip_message_t * sip, const char *start_of_buf, const charelse {/* if content_length does not exist, set it. */char tmp[16];-- /* case where content-length is missing but the- body only contains non-binary data */- if (0 == osip_strcasecmp (sip->content_type->type, "application")- && 0 == osip_strcasecmp (sip->content_type->subtype, "sdp")) {- osip_body_len = strlen (start_of_body);- sprintf (tmp, "%i", (int) osip_body_len);- i = osip_message_set_content_length (sip, tmp);- if (i != 0)- return i;- }- else- return OSIP_SYNTAXERROR; /* Content-type may be non binary data */+ osip_body_len = length;+ sprintf (tmp, "%i", (int) osip_body_len);+ i = osip_message_set_content_length (sip, tmp);+ if (i != 0)+ return i;}if (length < osip_body_len) {@@ -866,9 +858,19 @@ _osip_message_parse (osip_message_t * sip, const char *buf, size_t length, int s}tmp = (char *) next_header_index;- /* this is a *very* simple test... (which handle most cases...) */- if (tmp[0] == '\0' || tmp[1] == '\0' || tmp[2] == '\0') {- /* this is mantory in the oSIP stack */+ if (sip->content_length != NULL && sip->content_length->value == NULL) {+ /* empty content_length header */+ osip_content_length_free(sip->content_length);+ sip->content_length=NULL;+ }++ if (sip->content_length != NULL && sip->content_length->value != NULL && atoi(sip->content_length->value) >0) {+ /* body exist */+ } else if (sip->content_length == NULL && '\r' == next_header_index[0] && '\n' == next_header_index[1] && length - (tmp - beg) - (2) >0) {+ /* body exist */+ } else if (sip->content_length == NULL && '\n' == next_header_index[0] && length - (tmp - beg) - (1) >0) {+ /* body exist */+ } else {if (sip->content_length == NULL)osip_message_set_content_length (sip, "0");osip_free (beg);That's my final proposal!If you wish to report on this, I'll be interested to know opinions and experience.RegardsAymeric2015-01-30 10:27 GMT+01:00 Aymeric Moizard <address@hidden>:Hi Paul,Your other sip client is starting the body with "\0" andthat break the parsing? right?Having UTF16 inside the body is allowed and thus, \0is allowed as the first char in the body.Is this what you are reporting?Look like you are right. I'm working on a different patchwhich would be more compliant.What do you think about this: I think this is handling every case in an exact way.1/ if the content-length >0, we parse the body2/ if the content-length is missing (UDP/connection-less protocol), we trust the remaining "size"(if there is no content-length)3/ there is no check for \0 any more.diff --git a/src/osipparser2/osip_message_parse.c b/src/osipparser2/osip_message_parse.cindex e305cf0..8108fa8 100644--- a/src/osipparser2/osip_message_parse.c+++ b/src/osipparser2/osip_message_parse.c@@ -866,9 +866,19 @@ _osip_message_parse (osip_message_t * sip, const char *buf, size_t length, int s}tmp = (char *) next_header_index;- /* this is a *very* simple test... (which handle most cases...) */- if (tmp[0] == '\0' || tmp[1] == '\0' || tmp[2] == '\0') {- /* this is mantory in the oSIP stack */+ if (sip->content_length != NULL && sip->content_length->value == NULL) {+ /* empty content_length header */+ osip_content_length_free(sip->content_length);+ sip->content_length=NULL;+ }++ if (sip->content_length != NULL && sip->content_length->value != NULL && atoi(sip->content_length->value) >0) {+ /* body exist */+ } else if (sip->content_length == NULL && '\r' == next_header_index[0] && '\n' == next_header_index[1] && length - (tmp - beg) - (2) >0) {+ /* body exist */+ } else if (sip->content_length == NULL && '\n' == next_header_index[0] && length - (tmp - beg) - (1) >0) {+ /* body exist */+ } else {if (sip->content_length == NULL)osip_message_set_content_length (sip, "0");osip_free (beg);RegardsAymeric--2015-01-29 4:09 GMT+01:00 Paul Whitfield <address@hidden>:Hi All,
I have come across and issue using osip2 in a particular application.
The device I am communicating with sends a SIP message with content that is encoded as UTF16.
This device is from a 3rd party so I cannot change it L
This caused the test in osip_message_parse.c to fail. The following test
/* this is a *very* simple test... (which handle most cases...) */
if (tmp[0] == '\0' || tmp[1] == '\0' || tmp[2] == '\0')
{
/* this is mantory in the oSIP stack */
if (sip->content_length == NULL)
osip_message_set_content_length(sip, "0");
osip_free(beg);
return OSIP_SUCCESS; /* no body found */
}
I propose the following fix:
/* this is a *very* simple test... (which handle most cases...) */
/* IGNORE this test if we have a content length */
if ( ( ( sip->content_length == 0 ) || ( atoi(sip->content_length->value) == 0 ) ) &&
( (tmp[0] == '\0') || (tmp[1] == '\0' ) || (tmp[2] == '\0') ) )
{
/* this is mandatory in the oSIP stack */
if (sip->content_length == NULL)
{
osip_message_set_content_length(sip, "0");
}
osip_free(beg);
return OSIP_SUCCESS; /* no body found */
}
If this is acceptable I can make / send a patch against osip4.1.
Best regards
Paul Whitfield.
Example of the message that is causing the problem:
MESSAGE sip:address@hidden SIP/2.0
Via: SIP/2.0/UDP 192.168.20.203:5060;rport;branch=z9hG4bK7053
From: <sip:address@hidden>;tag=18062
To: <sip:address@hidden>
Call-ID: 8376
CSeq: 20 MESSAGE
Content-Type: text/plain; charset=utf-16
Max-Forwards: 70
User-Agent: HYTERA SIP 1.1
Ais-Reach: individual
Ais-Service: text-msg
Ais-Options: slot=1
Content-Length: 20
\000T\000h\000a\000n\000k\000 \000Y\000o\000u\000!
--
[Prev in Thread] | Current Thread | [Next in Thread] |