osip-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [osip-dev] Issue with osip_message_parse


From: Aymeric Moizard
Subject: Re: [osip-dev] Issue with osip_message_parse
Date: Fri, 30 Jan 2015 10:27:40 +0100

Hi Paul,

Your other sip client is starting the body with "\0" and
that break the parsing? right?

Having UTF16 inside the body is allowed and thus, \0
is 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 patch
which 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 body
2/ 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.c
index 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);

Regards
Aymeric


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!

 

 




--
Antisip - http://www.antisip.com

reply via email to

[Prev in Thread] Current Thread [Next in Thread]