Commit 2fcc8e7d authored by Pekka Pessi's avatar Pekka Pessi

msg_parser_util.c: fixed msg_unquoted_e()

Ignore-this: 78b9afb6e97ff730d7924d860ef33921

Now accepts NULL buffer with nonzero size.

Coverity issue.

darcs-hash:20090513180206-db55f-e8ed3ebb0000de487445830a2e6b2081daef4059.gz
parent f0b384b1
......@@ -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;
}
......
......@@ -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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment