[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Input validation observations

From: Noorul Islam K M <noorul_at_collab.net>
Date: Fri, 03 Dec 2010 17:11:12 +0530

Julian Foad <julian.foad_at_wandisco.com> writes:

> I tried some potentially invalid inputs to "svn" a week or two ago and
> made notes on what I found. Just posting here in case anyone wants to
> do something about one or more of them.
>
> Noorul, I'm including you in the "To" addresses because you said you
> were looking for more small tasks to do, so feel free to pick one of
> these if you want to.
>
> Where I end with a question mark, it means I'm not sure if we want this
> change, it's just a suggestion.
>
> * "svn mkdir ^/ a" -> "Illegal repository URL 'a'"; should say "can't
> mix URL and local targets"?
>

Patch attached

Log

[[[
Make 'svn mkdir' verify that both working copy paths and URLs are
not passed.

* subversion/svn/mkdir-cmd.c,
  subversion/libsvn_client/add.c
  (svn_cl__mkdir, svn_client_mkdir4): Raise an error if both working
  copy paths and URLs are passed.

* subversion/tests/cmdline/input_validation_tests.py
  (invalid_mkdir_targets, test_list): New test

Patch by: Noorul Islam K M <noorul{_AT_}collab.net>
]]]

Index: subversion/tests/cmdline/input_validation_tests.py
===================================================================
--- subversion/tests/cmdline/input_validation_tests.py (revision 1041293)
+++ subversion/tests/cmdline/input_validation_tests.py (working copy)
@@ -234,6 +234,12 @@
   run_and_verify_svn_in_wc(sbox, "svn:.*is not a local path", 'relocate',
                            "^/", "^/", "^/")
 
+def invalid_mkdir_targets(sbox):
+ "invalid targets for 'mkdir'"
+ sbox.build(read_only=True)
+ run_and_verify_svn_in_wc(sbox, "svn: Cannot mix repository and working "
+ "copy targets", 'mkdir', "folder", "^/folder")
+
 ########################################################################
 # Run the tests
 
@@ -261,6 +267,7 @@
               invalid_patch_targets,
               invalid_switch_targets,
               invalid_relocate_targets,
+ invalid_mkdir_targets,
              ]
 
 if __name__ == '__main__':
Index: subversion/svn/mkdir-cmd.c
===================================================================
--- subversion/svn/mkdir-cmd.c (revision 1041293)
+++ subversion/svn/mkdir-cmd.c (working copy)
@@ -48,6 +48,8 @@
   svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
   apr_array_header_t *targets;
   svn_error_t *err;
+ svn_boolean_t wc_present = FALSE, url_present = FALSE;
+ int i;
 
   SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
                                                       opt_state->targets,
@@ -56,6 +58,22 @@
   if (! targets->nelts)
     return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
 
+ /* Check to see if at least one of our paths is a working copy
+ path or a repository url. */
+ for (i = 0; i < targets->nelts; ++i)
+ {
+ const char *target = APR_ARRAY_IDX(targets, i, const char *);
+ if (! svn_path_is_url(target))
+ wc_present = TRUE;
+ else
+ url_present = TRUE;
+ }
+
+ if (url_present && wc_present)
+ return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+ _("Cannot mix repository and working copy "
+ "targets"));
+
   if (! svn_path_is_url(APR_ARRAY_IDX(targets, 0, const char *)))
     {
       ctx->log_msg_func3 = NULL;
Index: subversion/libsvn_client/add.c
===================================================================
--- subversion/libsvn_client/add.c (revision 1041293)
+++ subversion/libsvn_client/add.c (working copy)
@@ -875,9 +875,28 @@
                   svn_client_ctx_t *ctx,
                   apr_pool_t *pool)
 {
+ svn_boolean_t wc_present = FALSE, url_present = FALSE;
+ int i;
+
   if (! paths->nelts)
     return SVN_NO_ERROR;
 
+ /* Check to see if at least one of our paths is a working copy
+ path or a repository url. */
+ for (i = 0; i < paths->nelts; ++i)
+ {
+ const char *path = APR_ARRAY_IDX(paths, i, const char *);
+ if (! svn_path_is_url(path))
+ wc_present = TRUE;
+ else
+ url_present = TRUE;
+ }
+
+ if (url_present && wc_present)
+ return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
+ _("Cannot mix repository and working copy "
+ "targets"));
+
   if (svn_path_is_url(APR_ARRAY_IDX(paths, 0, const char *)))
     {
       SVN_ERR(mkdir_urls(paths, make_parents, revprop_table, commit_callback,
@@ -887,7 +906,6 @@
     {
       /* This is a regular "mkdir" + "svn add" */
       apr_pool_t *subpool = svn_pool_create(pool);
- int i;
 
       for (i = 0; i < paths->nelts; i++)
         {
Received on 2010-12-03 12:43:48 CET

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.