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 2013/05/19 11:57:12 UTC
svn commit: r1484250 - in /subversion/branches/1.6.x-issue4340-repos: ./
subversion/libsvn_repos/commit.c subversion/tests/libsvn_repos/repos-test.c
Author: stsp
Date: Sun May 19 09:57:12 2013
New Revision: 1484250
URL: http://svn.apache.org/r1484250
Log:
On the 1.6.x-issue4340-repos branch, merge r1480948 from trunk, resolving
conflicts.
Modified:
subversion/branches/1.6.x-issue4340-repos/ (props changed)
subversion/branches/1.6.x-issue4340-repos/subversion/libsvn_repos/commit.c
subversion/branches/1.6.x-issue4340-repos/subversion/tests/libsvn_repos/repos-test.c
Propchange: subversion/branches/1.6.x-issue4340-repos/
------------------------------------------------------------------------------
Merged /subversion/trunk:r1461760
Modified: subversion/branches/1.6.x-issue4340-repos/subversion/libsvn_repos/commit.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.6.x-issue4340-repos/subversion/libsvn_repos/commit.c?rev=1484250&r1=1484249&r2=1484250&view=diff
==============================================================================
--- subversion/branches/1.6.x-issue4340-repos/subversion/libsvn_repos/commit.c (original)
+++ subversion/branches/1.6.x-issue4340-repos/subversion/libsvn_repos/commit.c Sun May 19 09:57:12 2013
@@ -29,6 +29,7 @@
#include "svn_fs.h"
#include "svn_repos.h"
#include "svn_checksum.h"
+#include "svn_ctype.h"
#include "svn_props.h"
#include "svn_mergeinfo.h"
#include "repos.h"
@@ -160,6 +161,78 @@ check_authz(struct edit_baton *editor_ba
return SVN_NO_ERROR;
}
+/* Return a copy of PATH, allocated from POOL, for which control
+ characters have been escaped using the form \NNN (where NNN is the
+ octal representation of the byte's ordinal value). */
+static const char *
+illegal_path_escape(const char *path, apr_pool_t *pool)
+{
+ svn_stringbuf_t *retstr;
+ apr_size_t i, copied = 0;
+ int c;
+
+ /* At least one control character:
+ strlen - 1 (control) + \ + N + N + N + null . */
+ retstr = svn_stringbuf_create_ensure(strlen(path) + 4, pool);
+ for (i = 0; path[i]; i++)
+ {
+ c = (unsigned char)path[i];
+ if (! svn_ctype_iscntrl(c))
+ continue;
+
+ /* If we got here, we're looking at a character that isn't
+ supported by the (or at least, our) URI encoding scheme. We
+ need to escape this character. */
+
+ /* First things first, copy all the good stuff that we haven't
+ yet copied into our output buffer. */
+ if (i - copied)
+ svn_stringbuf_appendbytes(retstr, path + copied,
+ i - copied);
+
+ /* Make sure buffer is big enough for '\' 'N' 'N' 'N' (and NUL) */
+ svn_stringbuf_ensure(retstr, retstr->len + 4);
+ /*### The backslash separator doesn't work too great with Windows,
+ but it's what we'll use for consistency with invalid utf8
+ formatting (until someone has a better idea) */
+ apr_snprintf(retstr->data + retstr->len, 5, "\\%03o", (unsigned char)c);
+ retstr->len += 4;
+
+ /* Finally, update our copy counter. */
+ copied = i + 1;
+ }
+
+ /* If we didn't encode anything, we don't need to duplicate the string. */
+ if (retstr->len == 0)
+ return path;
+
+ /* Anything left to copy? */
+ if (i - copied)
+ svn_stringbuf_appendbytes(retstr, path + copied, i - copied);
+
+ /* retstr is null-terminated either by apr_snprintf or the svn_stringbuf
+ functions. */
+
+ return retstr->data;
+}
+
+static svn_error_t *
+check_cntrl(const char *path,
+ apr_pool_t *pool)
+{
+ const char *c;
+
+ for (c = path; *c; c++)
+ {
+ if (svn_ctype_iscntrl(*c))
+ return svn_error_createf(SVN_ERR_FS_PATH_SYNTAX, NULL,
+ _("Invalid control character '0x%02x' in path '%s'"),
+ (unsigned char)*c, illegal_path_escape(path, pool));
+ }
+
+ return SVN_NO_ERROR;
+}
+
/*** Editor functions ***/
@@ -291,6 +364,9 @@ add_directory(const char *path,
apr_pool_t *subpool = svn_pool_create(pool);
svn_boolean_t was_copied = FALSE;
+ /* Reject paths which contain control characters (related to issue #4340). */
+ SVN_ERR(check_cntrl(path, pool));
+
/* Sanity check. */
if (copy_path && (! SVN_IS_VALID_REVNUM(copy_revision)))
return svn_error_createf
@@ -436,6 +512,9 @@ add_file(const char *path,
const char *full_path = svn_path_join(eb->base_path, path, pool);
apr_pool_t *subpool = svn_pool_create(pool);
+ /* Reject paths which contain control characters (related to issue #4340). */
+ SVN_ERR(check_cntrl(path, pool));
+
/* Sanity check. */
if (copy_path && (! SVN_IS_VALID_REVNUM(copy_revision)))
return svn_error_createf
Modified: subversion/branches/1.6.x-issue4340-repos/subversion/tests/libsvn_repos/repos-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.6.x-issue4340-repos/subversion/tests/libsvn_repos/repos-test.c?rev=1484250&r1=1484249&r2=1484250&view=diff
==============================================================================
--- subversion/branches/1.6.x-issue4340-repos/subversion/tests/libsvn_repos/repos-test.c (original)
+++ subversion/branches/1.6.x-issue4340-repos/subversion/tests/libsvn_repos/repos-test.c Sun May 19 09:57:12 2013
@@ -2462,6 +2462,111 @@ get_logs(const char **msg,
}
+
+/* Related to issue 4340, "fs layer should reject filenames with trailing \n" */
+static svn_error_t *
+filename_with_control_chars(const char **msg,
+ svn_boolean_t msg_only,
+ svn_test_opts_t *opts,
+ apr_pool_t *pool)
+{
+ apr_pool_t *subpool = svn_pool_create(pool);
+ svn_repos_t *repos;
+ svn_fs_t *fs;
+ svn_fs_txn_t *txn;
+ svn_fs_root_t *txn_root;
+ svn_revnum_t youngest_rev = 0;
+ svn_error_t *err;
+ static const char *bad_paths[] = {
+ "/bar\t",
+ "/bar\n",
+ "/\barb\az",
+ "/\x02 baz",
+ NULL,
+ };
+ const char *p;
+ int i;
+ void *edit_baton;
+ void *root_baton;
+ void *out_baton;
+ const svn_delta_editor_t *editor;
+
+ *msg = "test filenames with control characters";
+
+ if (msg_only)
+ return SVN_NO_ERROR;
+
+ /* Create the repository. */
+ SVN_ERR(svn_test__create_repos(&repos, "test-repos-filename-with-cntrl-chars",
+ opts, pool));
+ fs = svn_repos_fs(repos);
+
+ /* Revision 1: Add a directory /foo */
+ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, subpool));
+ SVN_ERR(svn_fs_txn_root(&txn_root, txn, subpool));
+ SVN_ERR(svn_fs_make_dir(txn_root, "/foo", subpool));
+ SVN_ERR(svn_repos_fs_commit_txn(NULL, repos, &youngest_rev, txn, subpool));
+ SVN_TEST_ASSERT(SVN_IS_VALID_REVNUM(youngest_rev));
+ svn_pool_clear(subpool);
+
+ /* Checks for control characters are implemented in the commit editor,
+ * not in the FS API. */
+ SVN_ERR(svn_fs_begin_txn(&txn, fs, youngest_rev, pool));
+ SVN_ERR(svn_repos_get_commit_editor4(&editor, &edit_baton, repos,
+ txn, "file://test", "/",
+ "plato", "test commit",
+ dummy_commit_cb, NULL, NULL, NULL,
+ pool));
+
+ SVN_ERR(editor->open_root(edit_baton, 1, pool, &root_baton));
+
+ /* Attempt to copy /foo to a bad path P. This should fail. */
+ i = 0;
+ do
+ {
+ p = bad_paths[i++];
+ if (p == NULL)
+ break;
+ svn_pool_clear(subpool);
+ err = editor->add_directory(p, root_baton, "/foo", 1, subpool,
+ &out_baton);
+ SVN_TEST_ASSERT(err && err->apr_err == SVN_ERR_FS_PATH_SYNTAX);
+ svn_error_clear(err);
+ } while (p);
+
+ /* Attempt to add a file with bad path P. This should fail. */
+ i = 0;
+ do
+ {
+ p = bad_paths[i++];
+ if (p == NULL)
+ break;
+ svn_pool_clear(subpool);
+ err = editor->add_file(p, root_baton, NULL, SVN_INVALID_REVNUM,
+ subpool, &out_baton);
+ SVN_TEST_ASSERT(err && err->apr_err == SVN_ERR_FS_PATH_SYNTAX);
+ svn_error_clear(err);
+ } while (p);
+
+
+ /* Attempt to add a directory with bad path P. This should fail. */
+ i = 0;
+ do
+ {
+ p = bad_paths[i++];
+ if (p == NULL)
+ break;
+ svn_pool_clear(subpool);
+ err = editor->add_directory(p, root_baton, NULL, SVN_INVALID_REVNUM,
+ subpool, &out_baton);
+ SVN_TEST_ASSERT(err && err->apr_err == SVN_ERR_FS_PATH_SYNTAX);
+ svn_error_clear(err);
+ } while (p);
+
+ SVN_ERR(editor->abort_edit(edit_baton, subpool));
+
+ return SVN_NO_ERROR;
+}
/* The test table. */
@@ -2481,5 +2586,6 @@ struct svn_test_descriptor_t test_funcs[
SVN_TEST_PASS(reporter_depth_exclude),
SVN_TEST_PASS(prop_validation),
SVN_TEST_PASS(get_logs),
+ SVN_TEST_PASS(filename_with_control_chars),
SVN_TEST_NULL
};