You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2015/01/11 00:46:28 UTC

svn commit: r1650834 - in /subversion/trunk/subversion: libsvn_subr/string.c tests/libsvn_subr/string-test.c

Author: stefan2
Date: Sat Jan 10 23:46:28 2015
New Revision: 1650834

URL: http://svn.apache.org/r1650834
Log:
Fix stringbuf insertion and replacement for the case that the source is
within the target string itself and contains NUL chars.  Also, make the
test cases cover data containing NUL for those operations.

* subversion/libsvn_subr/string.c
  (svn_stringbuf_insert,
   svn_stringbuf_replace): Since the source data is binary, we need a binary
                           temp. copy - not a string-y one.

* subversion/tests/libsvn_subr/string-test.c
  (test_stringbuf_insert,
   test_stringbuf_replace): Add calls that insert strings containing NUL
                            and insert NULs from within the string.

Found by: julianfoad

Modified:
    subversion/trunk/subversion/libsvn_subr/string.c
    subversion/trunk/subversion/tests/libsvn_subr/string-test.c

Modified: subversion/trunk/subversion/libsvn_subr/string.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/string.c?rev=1650834&r1=1650833&r2=1650834&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/string.c (original)
+++ subversion/trunk/subversion/libsvn_subr/string.c Sat Jan 10 23:46:28 2015
@@ -658,7 +658,7 @@ svn_stringbuf_insert(svn_stringbuf_t *st
   if (bytes + count > str->data && bytes < str->data + str->blocksize)
     {
       /* special case: BYTES overlaps with this string -> copy the source */
-      const char *temp = apr_pstrndup(str->pool, bytes, count);
+      const char *temp = apr_pmemdup(str->pool, bytes, count);
       svn_stringbuf_insert(str, pos, temp, count);
     }
   else
@@ -706,7 +706,7 @@ svn_stringbuf_replace(svn_stringbuf_t *s
   if (bytes + new_count > str->data && bytes < str->data + str->blocksize)
     {
       /* special case: BYTES overlaps with this string -> copy the source */
-      const char *temp = apr_pstrndup(str->pool, bytes, new_count);
+      const char *temp = apr_pmemdup(str->pool, bytes, new_count);
       svn_stringbuf_replace(str, pos, old_count, temp, new_count);
     }
   else

Modified: subversion/trunk/subversion/tests/libsvn_subr/string-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/string-test.c?rev=1650834&r1=1650833&r2=1650834&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/string-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/string-test.c Sat Jan 10 23:46:28 2015
@@ -604,7 +604,19 @@ test_stringbuf_insert(apr_pool_t *pool)
   SVN_TEST_STRING_ASSERT(a->data, "test hello, world");
 
   svn_stringbuf_insert(a, 1200, "!", 1);
-  return expect_stringbuf_equal(a, "test hello, world!", pool);
+  SVN_TEST_STRING_ASSERT(a->data, "test hello, world!");
+
+  svn_stringbuf_insert(a, 4, "\0-\0", 3);
+  SVN_TEST_ASSERT(svn_stringbuf_compare(a,
+                    svn_stringbuf_ncreate("test\0-\0 hello, world!",
+                                          21, pool)));
+
+  svn_stringbuf_insert(a, 14, a->data + 4, 3);
+  SVN_TEST_ASSERT(svn_stringbuf_compare(a,
+                    svn_stringbuf_ncreate("test\0-\0 hello,\0-\0 world!",
+                                          24, pool)));
+
+  return SVN_NO_ERROR;
 }
 
 static svn_error_t *
@@ -643,8 +655,24 @@ test_stringbuf_replace(apr_pool_t *pool)
   SVN_TEST_STRING_ASSERT(a->data, "test hello, world!");
 
   svn_stringbuf_replace(a, 1200, 199, "!!", 2);
+  SVN_TEST_STRING_ASSERT(a->data, "test hello, world!!!");
+
+  svn_stringbuf_replace(a, 10, 2, "\0-\0", 3);
+  SVN_TEST_ASSERT(svn_stringbuf_compare(a,
+                    svn_stringbuf_ncreate("test hello\0-\0world!!!",
+                                          21, pool)));
+
+  svn_stringbuf_replace(a, 10, 3, a->data + 10, 3);
+  SVN_TEST_ASSERT(svn_stringbuf_compare(a,
+                    svn_stringbuf_ncreate("test hello\0-\0world!!!",
+                                          21, pool)));
+
+  svn_stringbuf_replace(a, 19, 1, a->data + 10, 3);
+  SVN_TEST_ASSERT(svn_stringbuf_compare(a,
+                    svn_stringbuf_ncreate("test hello\0-\0world!\0-\0!",
+                                          23, pool)));
 
-  return expect_stringbuf_equal(a, "test hello, world!!!", pool);
+  return SVN_NO_ERROR;
 }
 
 static svn_error_t *