[Freeswitch-svn] [commit] r13346 - in freeswitch/trunk/libs/sofia-sip: . libsofia-sip-ua/msg

FreeSWITCH SVN mikej at freeswitch.org
Fri May 15 09:13:21 PDT 2009


Author: mikej
Date: Fri May 15 11:13:20 2009
New Revision: 13346

Log:
Wed May 13 13:02:06 CDT 2009  Pekka Pessi <first.last at nokia.com>
  * msg_parser_util.c: fixed msg_unquoted_e()
  Ignore-this: 78b9afb6e97ff730d7924d860ef33921
  
  Now accepts NULL buffer with nonzero size.
  
  Coverity issue.


Modified:
   freeswitch/trunk/libs/sofia-sip/.update
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser_util.c
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/test_msg.c

Modified: freeswitch/trunk/libs/sofia-sip/.update
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/.update	(original)
+++ freeswitch/trunk/libs/sofia-sip/.update	Fri May 15 11:13:20 2009
@@ -1 +1 @@
-Fri May 15 11:12:29 CDT 2009
+Fri May 15 11:13:02 CDT 2009

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser_util.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser_util.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser_util.c	Fri May 15 11:13:20 2009
@@ -1741,35 +1741,37 @@
 /** Quote string */
 issize_t msg_unquoted_e(char *b, isize_t bsiz, char const *s)
 {
-  char *begin = b;
-  char *end = b + bsiz;
+  isize_t e = 0;
 
-  if (b && b + 1 < end)
+  if (b == NULL)
+    bsiz = 0;
+
+  if (0 < bsiz)
     *b = '"';
-  b++;
+  e++;
 
   for (;*s;) {
     size_t n = strcspn(s, "\"\\");
 
     if (n == 0) {
-      if (b && b + 2 < end)
-	b[0] = '\\', b[1] = s[0];
-      b += 2;
+      if (e + 2 <= bsiz)
+	b[e] = '\\', b[e + 1] = s[0];
+      e += 2;
       s++;
     }
     else {
-      if (b && b + n < end)
-	memcpy(b, s, n);
-      b += n;
+      if (e + n <= bsiz)
+	memcpy(b + e, s, n);
+      e += n;
       s += n;
     }
   }
 
-  if (b && b + 1 < end)
-    *b = '"';
-  b++;
+  if (e < bsiz)
+    b[e] = '"';
+  e++;
 
-  return b - begin;
+  return e;
 }
 
 

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/test_msg.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/test_msg.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/test_msg.c	Fri May 15 11:13:20 2009
@@ -496,6 +496,22 @@
     su_home_deinit(home);
   }
 
+  {
+    char b[8];
+    TEST(msg_unquoted_e(NULL, 0, "\"\""), 6);
+    TEST(msg_unquoted_e(b, 0, "\"\""), 6);
+    TEST(msg_unquoted_e(b, 4, "\"\""), 6);
+    TEST(msg_unquoted_e(b, 6, "\"\""), 6);
+    TEST(memcmp(b, "\"\\\"\\\"\"", 6), 0);
+    TEST(msg_unquoted_e(b, 4, "\""), 4);
+    memset(b, 0, sizeof b);
+    TEST(msg_unquoted_e(b, 1, "\"kuik"), 8);
+    TEST(memcmp(b, "\"\0", 2), 0);
+    TEST(msg_unquoted_e(b, 3, "\"kuik"), 8);
+    TEST(memcmp(b, "\"\\\"\0", 4), 0);
+    TEST(msg_unquoted_e(b, 7, "\"kuik"), 8);
+    TEST(memcmp(b, "\"\\\"kuik\0", 8), 0);
+  }
 
   END();
 }



More information about the Freeswitch-svn mailing list