You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ph...@apache.org on 2012/08/23 11:03:48 UTC

svn commit: r1376414 - in /subversion/trunk/subversion: libsvn_subr/dirent_uri.c tests/libsvn_subr/dirent_uri-test.c

Author: philip
Date: Thu Aug 23 09:03:46 2012
New Revision: 1376414

URL: http://svn.apache.org/viewvc?rev=1376414&view=rev
Log:
Fix a memory read bug.

Found by: Tony Butt <tjb{AT}cea.com.au>

* subversion/libsvn_subr/dirent_uri.c
  (svn_dirent_skip_ancestor, svn_relpath_skip_ancestor,
   uri_skip_ancestor): Don't read beyond end of child.

* subversion/tests/libsvn_subr/dirent_uri-test.c
  (dirent_ancestor_tests, uri_ancestor_tests): Extend.

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

Modified: subversion/trunk/subversion/libsvn_subr/dirent_uri.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/dirent_uri.c?rev=1376414&r1=1376413&r2=1376414&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/dirent_uri.c (original)
+++ subversion/trunk/subversion/libsvn_subr/dirent_uri.c Thu Aug 23 09:03:46 2012
@@ -1401,7 +1401,7 @@ svn_dirent_skip_ancestor(const char *par
   apr_size_t len = strlen(parent_dirent);
   apr_size_t root_len;
 
-  if (0 != memcmp(parent_dirent, child_dirent, len))
+  if (0 != strncmp(parent_dirent, child_dirent, len))
     return NULL; /* parent_dirent is no ancestor of child_dirent */
 
   if (child_dirent[len] == 0)
@@ -1459,7 +1459,7 @@ svn_relpath_skip_ancestor(const char *pa
   if (len == 0)
     return child_relpath;
 
-  if (0 != memcmp(parent_relpath, child_relpath, len))
+  if (0 != strncmp(parent_relpath, child_relpath, len))
     return NULL; /* parent_relpath is no ancestor of child_relpath */
 
   if (child_relpath[len] == 0)
@@ -1482,7 +1482,7 @@ uri_skip_ancestor(const char *parent_uri
   assert(svn_uri_is_canonical(parent_uri, NULL));
   assert(svn_uri_is_canonical(child_uri, NULL));
 
-  if (0 != memcmp(parent_uri, child_uri, len))
+  if (0 != strncmp(parent_uri, child_uri, len))
     return NULL; /* parent_uri is no ancestor of child_uri */
 
   if (child_uri[len] == 0)

Modified: subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c?rev=1376414&r1=1376413&r2=1376414&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/dirent_uri-test.c Thu Aug 23 09:03:46 2012
@@ -1364,6 +1364,9 @@ static const testcase_ancestor_t dirent_
     { "foo.",           "foo./.bar",        ".bar" },
     { "X:foo",          "X:bar",            NULL },
     { "../foo",         "..",               NULL },
+    { "/foo/bar/zig",   "/foo",             NULL },
+    { "/foo/bar/zig",   "/foo/ba",          NULL },
+    { "/foo/bar/zig",   "/foo/bar/zi",      NULL },
 #ifdef SVN_USE_DOS_PATHS
     { "",               "C:",               NULL },
     { "",               "C:foo",            NULL },
@@ -1384,6 +1387,9 @@ static const testcase_ancestor_t dirent_
     { "X:/foo",         "X:/",              NULL },
     { "A:/foo",         "A:/foo/bar",       "bar" },
     { "A:/foo",         "A:/foot",          NULL },
+    { "A:/foo/bar/zig", "A:/foo",           NULL },
+    { "A:/foo/bar/zig", "A:/foo/ba",        NULL },
+    { "A:/foo/bar/zig", "A:/foo/bar/zi",    NULL },
     { "//srv",          "//srv/share",      NULL },
     { "//srv",          "//srv/shr/fld",    NULL },
     { "//srv/shr",      "//srv",            NULL },
@@ -1393,6 +1399,7 @@ static const testcase_ancestor_t dirent_
     { "//srv/s r",      "//srv/s r/fld",    "fld" },
     { "//srv/shr/fld",  "//srv/shr",        NULL },
     { "//srv/shr/fld",  "//srv2/shr/fld",   NULL },
+    { "//srv/shr/fld",  "//srv/shr/f",      NULL },
     { "/",              "//srv/share",      NULL },
 #else /* !SVN_USE_DOS_PATHS */
     { "",               "C:",               "C:" },
@@ -1458,6 +1465,8 @@ static const testcase_ancestor_t uri_anc
     { "http://",        "http://test",      NULL },
     { "http://server",  "http://server/q",  "q" },
     { "svn://server",   "http://server/q",  NULL },
+    { "http://foo/bar", "http://foo",       NULL },
+    { "http://foo/bar", "http://foo/ba",    NULL },
   };
 
 static svn_error_t *