subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From julianf...@apache.org
Subject svn commit: r1137616 - in /subversion/trunk/subversion: libsvn_client/patch.c libsvn_wc/update_editor.c
Date Mon, 20 Jun 2011 12:54:16 GMT
Author: julianfoad
Date: Mon Jun 20 12:54:16 2011
New Revision: 1137616

URL: http://svn.apache.org/viewvc?rev=1137616&view=rev
Log:
Code simplification around the use of svn_dirent_is_under_root().

* subversion/libsvn_client/patch.c
  (resolve_target_path): Eliminate a svn_dirent_get_absolute() call and a
    variable.

* subversion/libsvn_wc/update_editor.c
  (check_path_under_root): Rename to path_join_under_root() and add a
    result_path parameter.
  (make_dir_baton, make_file_baton): Call path_join_under_root() here
    instead of svn_dirent_join() ...
  (add_directory, open_directory, add_file, open_file): ... and eliminate
    the check_path_under_root() call here.
  (delete_entry): Use path_join_under_root() instead of
    check_path_under_root() and svn_dirent_join().

Modified:
    subversion/trunk/subversion/libsvn_client/patch.c
    subversion/trunk/subversion/libsvn_wc/update_editor.c

Modified: subversion/trunk/subversion/libsvn_client/patch.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/patch.c?rev=1137616&r1=1137615&r2=1137616&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Mon Jun 20 12:54:16 2011
@@ -373,7 +373,6 @@ resolve_target_path(patch_target_t *targ
                     apr_pool_t *scratch_pool)
 {
   const char *stripped_path;
-  const char *full_path;
   svn_wc_status3_t *status;
   svn_error_t *err;
   svn_boolean_t under_root;
@@ -420,7 +419,7 @@ resolve_target_path(patch_target_t *targ
   /* Make sure the path is secure to use. We want the target to be inside
    * of the working copy and not be fooled by symlinks it might contain. */
   SVN_ERR(svn_dirent_is_under_root(&under_root,
-                                   &full_path, local_abspath,
+                                   &target->local_abspath, local_abspath,
                                    target->local_relpath, result_pool));
 
   if (! under_root)
@@ -431,9 +430,6 @@ resolve_target_path(patch_target_t *targ
       return SVN_NO_ERROR;
     }
 
-  SVN_ERR(svn_dirent_get_absolute(&target->local_abspath, full_path,
-                                  result_pool));
-
   /* Skip things we should not be messing with. */
   err = svn_wc_status3(&status, wc_ctx, target->local_abspath,
                        result_pool, scratch_pool);

Modified: subversion/trunk/subversion/libsvn_wc/update_editor.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/update_editor.c?rev=1137616&r1=1137615&r2=1137616&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/update_editor.c (original)
+++ subversion/trunk/subversion/libsvn_wc/update_editor.c Mon Jun 20 12:54:16 2011
@@ -57,6 +57,12 @@
             (status) != svn_wc__db_status_excluded &&       \
             (status) != svn_wc__db_status_not_present)
 
+static svn_error_t *
+path_join_under_root(const char **result_path,
+                     const char *base_path,
+                     const char *add_path,
+                     apr_pool_t *result_pool);
+
 
 /*
  * This code handles "checkout" and "update" and "switch".
@@ -521,7 +527,8 @@ make_dir_baton(struct dir_baton **d_p,
   if (path)
     {
       d->name = svn_dirent_basename(path, dir_pool);
-      d->local_abspath = svn_dirent_join(pb->local_abspath, d->name, dir_pool);
+      SVN_ERR(path_join_under_root(&d->local_abspath,
+                                   pb->local_abspath, d->name, dir_pool));
     }
   else
     {
@@ -775,7 +782,8 @@ make_file_baton(struct file_baton **f_p,
   /* Make the file's on-disk name. */
   f->name = svn_dirent_basename(path, file_pool);
   f->old_revision = SVN_INVALID_REVNUM;
-  f->local_abspath = svn_dirent_join(pb->local_abspath, f->name, file_pool);
+  SVN_ERR(path_join_under_root(&f->local_abspath,
+                               pb->local_abspath, f->name, file_pool));
 
   /* Figure out the new_URL for this file. */
   if (adding || pb->edit_baton->switch_relpath)
@@ -993,9 +1001,9 @@ accumulate_last_change(svn_revnum_t *cha
 }
 
 
-/* Check that when ADD_PATH is joined to BASE_PATH, the resulting path
- * is still under BASE_PATH in the local filesystem.  If not, return
- * SVN_ERR_WC_OBSTRUCTED_UPDATE; else return success.
+/* Join ADD_PATH to BASE_PATH.  If ADD_PATH is absolute, or if any ".."
+ * component of it resolves to a path above BASE_PATH, then return
+ * SVN_ERR_WC_OBSTRUCTED_UPDATE.
  *
  * This is to prevent the situation where the repository contains,
  * say, "..\nastyfile".  Although that's perfectly legal on some
@@ -1005,23 +1013,23 @@ accumulate_last_change(svn_revnum_t *cha
  * (http://cve.mitre.org/cgi-bin/cvename.cgi?name=2007-3846)
  */
 static svn_error_t *
-check_path_under_root(const char *base_path,
-                      const char *add_path,
-                      apr_pool_t *scratch_pool)
+path_join_under_root(const char **result_path,
+                     const char *base_path,
+                     const char *add_path,
+                     apr_pool_t *pool)
 {
   svn_boolean_t under_root;
 
-  SVN_ERR(svn_dirent_is_under_root(&under_root, NULL, base_path, add_path,
-                                   scratch_pool));
+  SVN_ERR(svn_dirent_is_under_root(&under_root,
+                                   result_path, base_path, add_path, pool));
 
   if (! under_root)
     {
       return svn_error_createf(
           SVN_ERR_WC_OBSTRUCTED_UPDATE, NULL,
-         _("Path '%s' is not in the working copy"),
-         svn_dirent_local_style(svn_dirent_join(base_path, add_path,
-                                                scratch_pool),
-                                scratch_pool));
+          _("Path '%s' is not in the working copy"),
+          svn_dirent_local_style(svn_dirent_join(base_path, add_path, pool),
+                                 pool));
     }
 
   return SVN_NO_ERROR;
@@ -1677,9 +1685,8 @@ delete_entry(const char *path,
 
   SVN_ERR(mark_directory_edited(pb, scratch_pool));
 
-  SVN_ERR(check_path_under_root(pb->local_abspath, base, scratch_pool));
-
-  local_abspath = svn_dirent_join(pb->local_abspath, base, scratch_pool);
+  SVN_ERR(path_join_under_root(&local_abspath, pb->local_abspath, base,
+                               scratch_pool));
 
   deleting_target =  (strcmp(local_abspath, eb->target_abspath) == 0);
 
@@ -1907,8 +1914,6 @@ add_directory(const char *path,
 
   SVN_ERR(mark_directory_edited(db, pool));
 
-  SVN_ERR(check_path_under_root(pb->local_abspath, db->name, pool));
-
   if (strcmp(eb->target_abspath, db->local_abspath) == 0)
     {
       /* The target of the edit is being added, give it the requested
@@ -2248,8 +2253,6 @@ open_directory(const char *path,
   if (db->skip_this)
     return SVN_NO_ERROR;
 
-  SVN_ERR(check_path_under_root(pb->local_abspath, db->name, pool));
-
   /* Detect obstructing working copies */
   {
     svn_boolean_t is_root;
@@ -2950,8 +2953,6 @@ add_file(const char *path,
 
   SVN_ERR(mark_file_edited(fb, pool));
 
-  SVN_ERR(check_path_under_root(pb->local_abspath, fb->name, pool));
-
   /* The file_pool can stick around for a *long* time, so we want to
      use a subpool for any temporary allocations. */
   scratch_pool = svn_pool_create(pool);
@@ -3244,8 +3245,6 @@ open_file(const char *path,
   if (fb->skip_this)
     return SVN_NO_ERROR;
 
-  SVN_ERR(check_path_under_root(pb->local_abspath, fb->name, scratch_pool));
-
   /* Detect obstructing working copies */
   {
     svn_boolean_t is_root;



Mime
View raw message