Wed May 13 13:02:06 CDT 2009 Pekka Pessi <first.last@nokia.com>

* 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
This commit is contained in:
Michael Jerris 2009-05-15 16:13:20 +00:00
parent be1650e4ea
commit 935a1433d6
3 changed files with 33 additions and 15 deletions

View File

@ -1 +1 @@
Fri May 15 11:12:29 CDT 2009
Fri May 15 11:13:02 CDT 2009

View File

@ -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;
}

View File

@ -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();
}