Commit 87ea5918 authored by bescoto's avatar bescoto

Fixed bug in Gruenbach's code and added test for it


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@405 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent c342884a
...@@ -283,23 +283,25 @@ int high_water_alloc(void **buf, size_t *bufsize, size_t newsize) ...@@ -283,23 +283,25 @@ int high_water_alloc(void **buf, size_t *bufsize, size_t newsize)
const char *quote(const char *str) const char *quote(const char *str)
{ {
static char *quoted_str; static char *quoted_str = NULL;
static size_t quoted_str_len; static size_t quoted_str_len = 0;
const unsigned char *s; const unsigned char *s;
char *q; char *q;
size_t nonpr; size_t nonpr, total_len;
if (!str) if (!str)
return str; return str;
for (nonpr = 0, s = (unsigned char *)str; *s != '\0'; s++) for (nonpr = 0, s = (unsigned char *)str, total_len = 0;
if (!isprint(*s) || isspace(*s) || *s == '\\' || *s == '=') *s != '\0'; s++, total_len++) {
nonpr++; if (!isprint(*s) || isspace(*s) || *s == '\\' || *s == '=')
nonpr++;
}
if (nonpr == 0) if (nonpr == 0)
return str; return str;
if (high_water_alloc((void **)&quoted_str, &quoted_str_len, if (high_water_alloc((void **)&quoted_str, &quoted_str_len,
nonpr * 3 + 1)) nonpr * 3 + total_len + 1))
return NULL; return NULL;
for (s = (unsigned char *)str, q = quoted_str; *s != '\0'; s++) { for (s = (unsigned char *)str, q = quoted_str; *s != '\0'; s++) {
if (!isprint(*s) || isspace(*s) || *s == '\\' || *s == '=') { if (!isprint(*s) || isspace(*s) || *s == '\\' || *s == '=') {
......
...@@ -48,6 +48,15 @@ class CTest(unittest.TestCase): ...@@ -48,6 +48,15 @@ class CTest(unittest.TestCase):
assert C.acl_unquote('\\012') == '\n' assert C.acl_unquote('\\012') == '\n'
s = '\\\n\t\145\n\01==' s = '\\\n\t\145\n\01=='
assert C.acl_unquote(C.acl_quote(s)) == s assert C.acl_unquote(C.acl_quote(s)) == s
def test_acl_quoting2(self):
"""This string used to segfault the quoting code, try now"""
s = '\xd8\xab\xb1Wb\xae\xc5]\x8a\xbb\x15v*\xf4\x0f!\xf9>\xe2Y\x86\xbb\xab\xdbp\xb0\x84\x13k\x1d\xc2\xf1\xf5e\xa5U\x82\x9aUV\xa0\xf4\xdf4\xba\xfdX\x03\x82\x07s\xce\x9e\x8b\xb34\x04\x9f\x17 \xf4\x8f\xa6\xfa\x97\xab\xd8\xac\xda\x85\xdcKvC\xfa#\x94\x92\x9e\xc9\xb7\xc3_\x0f\x84g\x9aB\x11<=^\xdbM\x13\x96c\x8b\xa7|*"\\\'^$@#!(){}?+ ~` '
quoted = C.acl_quote(s)
assert C.acl_unquote(quoted) == s
def test_acl_quoting_equals(self):
"""Make sure the equals character is quoted"""
assert C.acl_quote('=') != '='
if __name__ == "__main__": unittest.main() if __name__ == "__main__": unittest.main()
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