From: Michael Jerris Date: Fri, 15 May 2009 16:13:20 +0000 (+0000) Subject: Wed May 13 13:02:06 CDT 2009 Pekka Pessi X-Git-Tag: v1.0.4~858 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=935a1433d63874f6b7495daa7b0aec7627dbca25;p=thirdparty%2Ffreeswitch.git Wed May 13 13:02:06 CDT 2009 Pekka Pessi * msg_parser_util.c: fixed msg_unquoted_e() Ignore-this: 78b9afb6e97ff730d7924d860ef33921 Now accepts NULL buffer with nonzero size. Coverity issue. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13346 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- diff --git a/libs/sofia-sip/.update b/libs/sofia-sip/.update index 9cd9f3a75e..dd48325edc 100644 --- a/libs/sofia-sip/.update +++ b/libs/sofia-sip/.update @@ -1 +1 @@ -Fri May 15 11:12:29 CDT 2009 +Fri May 15 11:13:02 CDT 2009 diff --git a/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser_util.c b/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser_util.c index 5dd5cf1a95..dcdeb2e5af 100644 --- a/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser_util.c +++ b/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser_util.c @@ -1741,35 +1741,37 @@ char *msg_unquote(char *dst, char const *s) /** 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; } diff --git a/libs/sofia-sip/libsofia-sip-ua/msg/test_msg.c b/libs/sofia-sip/libsofia-sip-ua/msg/test_msg.c index 0bff6a993b..5b88bb1d62 100644 --- a/libs/sofia-sip/libsofia-sip-ua/msg/test_msg.c +++ b/libs/sofia-sip/libsofia-sip-ua/msg/test_msg.c @@ -496,6 +496,22 @@ int test_header_parsing(void) 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(); }