Author: brane
Date: Fri Dec 14 14:55:42 2018
New Revision: 1848943
URL: http://svn.apache.org/viewvc?rev=1848943&view=rev
Log:
Add new dirent, relpath and URI canonicalization functions that
check and report canonicalization failures.
* subversion/include/svn_dirent_uri.h: Update top-level docstring.
(svn_dirent_canonicalize_safe,
svn_relpath_canonicalize_safe,
svn_uri_canonicalize_safe): New prototypes.
* subversion/include/svn_error_codes.h
(SVN_ERR_CANONICALIZATION_FAILED): New error code.
* subversion/libsvn_subr/dirent_uri.c
(svn_dirent_canonicalize_safe,
svn_relpath_canonicalize_safe,
svn_uri_canonicalize_safe): Implement..
Modified:
subversion/trunk/subversion/include/svn_dirent_uri.h
subversion/trunk/subversion/include/svn_error_codes.h
subversion/trunk/subversion/libsvn_subr/dirent_uri.c
Modified: subversion/trunk/subversion/include/svn_dirent_uri.h
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_dirent_uri.h?rev=1848943&r1=1848942&r2=1848943&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_dirent_uri.h (original)
+++ subversion/trunk/subversion/include/svn_dirent_uri.h Fri Dec 14 14:55:42
2018
@@ -60,12 +60,15 @@
* form, except:
*
* - @c svn_dirent_canonicalize()
+ * - @c svn_dirent_canonicalize_safe()
* - @c svn_dirent_is_canonical()
* - @c svn_dirent_internal_style()
* - @c svn_relpath_canonicalize()
+ * - @c svn_relpath_canonicalize_safe()
* - @c svn_relpath_is_canonical()
* - @c svn_relpath__internal_style()
* - @c svn_uri_canonicalize()
+ * - @c svn_uri_canonicalize_safe()
* - @c svn_uri_is_canonical()
*
* The Subversion codebase also recognizes some other classes of path:
@@ -473,6 +476,30 @@ const char *
svn_dirent_canonicalize(const char *dirent,
apr_pool_t *result_pool);
+/**
+ * Return a new @a *cannonical_dirent like @a dirent, but transformed such
+ * that some types of dirent specification redundancies are removed.
+ *
+ * Similar to svn_dirent_canonicalize() (which see), but returns an error
+ * if the @a dirent can not be canonicalized or of the result does not pass
+ * the svn_dirent_is_canonical() test.
+ *
+ * If the function fails and @a non_canonical_result is not @c NULL, the
+ * result of the failed canonicalization attempt will be returned in
+ * @a *non_canonical_result.
+ *
+ * Allocates the results in @a result_pool. Uses @a scratch_pool for
+ * temporary allocations.
+ *
+ * @since New in 1.12.
+ */
+svn_error_t *
+svn_dirent_canonicalize_safe(const char **canonical_dirent,
+ const char **non_canonical_result,
+ const char *dirent,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool);
+
/** Return a new relpath like @a relpath, but transformed such that some types
* of relpath specification redundancies are removed.
@@ -492,6 +519,31 @@ const char *
svn_relpath_canonicalize(const char *relpath,
apr_pool_t *result_pool);
+/**
+ * Return a new @a *canonical_relpath like @a relpath, but transformed such
+ * that some types of relpath specification redundancies are removed.
+ *
+ * Similar to svn_relpath_canonicalize() (which see), but returns an error
+ * if the @a relpath can not be canonicalized or of the result does not
+ * pass the svn_relpath_is_canonical() test.
+ *
+ * If the function fails and @a non_canonical_result is not @c NULL, the
+ * result of the failed canonicalization attempt will be returned in
+ * @a *non_canonical_result.
+ *
+ * Allocates the results in @a result_pool. Uses @a scratch_pool for
+ * temporary allocations.
+ *
+ * @since New in 1.12.
+ */
+
+svn_error_t *
+svn_relpath_canonicalize_safe(const char **canonical_relpath,
+ const char **non_canonical_result,
+ const char *relpath,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool);
+
/** Return a new uri like @a uri, but transformed such that some types
* of uri specification redundancies are removed.
@@ -516,6 +568,31 @@ const char *
svn_uri_canonicalize(const char *uri,
apr_pool_t *result_pool);
+/**
+ * Return a new @a *canonical_uri like @a uri, but transformed such that
+ * some types of uri specification redundancies are removed.
+ *
+ * Similar to svn_uri_canonicalize() (which see), but returns an error if
+ * the @a uri can not be canonicalized or of the result does not pass the
+ * svn_uri_is_canonical() test.
+ *
+ * If the function fails and @a non_canonical_result is not @c NULL, the
+ * result of the failed canonicalization attempt will be returned in
+ * @a *non_canonical_result.
+ *
+ * Allocates the results in @a result_pool. Uses @a scratch_pool for
+ * temporary allocations.
+ *
+ * @since New in 1.12.
+ */
+svn_error_t *
+svn_uri_canonicalize_safe(const char **canonical_uri,
+ const char **non_canonical_result,
+ const char *uri,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool);
+
+
/** Return @c TRUE iff @a dirent is canonical.
*
* Use @a scratch_pool for temporary allocations.
Modified: subversion/trunk/subversion/include/svn_error_codes.h
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_error_codes.h?rev=1848943&r1=1848942&r2=1848943&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_error_codes.h (original)
+++ subversion/trunk/subversion/include/svn_error_codes.h Fri Dec 14 14:55:42
2018
@@ -1482,6 +1482,11 @@ SVN_ERROR_START
SVN_ERR_MISC_CATEGORY_START + 46,
"LZ4 decompression failed")
+ /** @since New in 1.12. */
+ SVN_ERRDEF(SVN_ERR_CANONICALIZATION_FAILED,
+ SVN_ERR_MISC_CATEGORY_START + 47,
+ "Could not canonicalize path or URI")
+
/* command-line client errors */
SVN_ERRDEF(SVN_ERR_CL_ARG_PARSING_ERROR,
Modified: subversion/trunk/subversion/libsvn_subr/dirent_uri.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/dirent_uri.c?rev=1848943&r1=1848942&r2=1848943&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/dirent_uri.c (original)
+++ subversion/trunk/subversion/libsvn_subr/dirent_uri.c Fri Dec 14 14:55:42
2018
@@ -1646,12 +1646,60 @@ svn_uri_canonicalize(const char *uri, ap
return canonicalize(type_uri, uri, pool);
}
+svn_error_t *
+svn_uri_canonicalize_safe(const char **canonical_uri,
+ const char **non_canonical_result,
+ const char *uri,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
+{
+ const char *const result = svn_uri_canonicalize(uri, result_pool);
+ if (!svn_uri_is_canonical(result, scratch_pool))
+ {
+ if (non_canonical_result)
+ *non_canonical_result = result;
+
+ return svn_error_createf(
+ SVN_ERR_CANONICALIZATION_FAILED, NULL,
+ _("Could not canonicalize URI '%s'"
+ " (the result '%s' is not canonical)"),
+ uri, result);
+ }
+ *canonical_uri = result;
+ return SVN_NO_ERROR;
+}
+
const char *
svn_relpath_canonicalize(const char *relpath, apr_pool_t *pool)
{
return canonicalize(type_relpath, relpath, pool);
}
+svn_error_t *
+svn_relpath_canonicalize_safe(const char **canonical_relpath,
+ const char **non_canonical_result,
+ const char *relpath,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
+{
+ const char *const result = svn_relpath_canonicalize(relpath, result_pool);
+ if (!svn_relpath_is_canonical(result))
+ {
+ if (non_canonical_result)
+ *non_canonical_result = result;
+
+ return svn_error_createf(
+ SVN_ERR_CANONICALIZATION_FAILED, NULL,
+ _("Could not canonicalize relpath '%s'"
+ " (the result '%s' is not canonical)"),
+ relpath, result);
+ }
+
+ SVN_UNUSED(scratch_pool);
+ *canonical_relpath = result;
+ return SVN_NO_ERROR;
+}
+
const char *
svn_dirent_canonicalize(const char *dirent, apr_pool_t *pool)
{
@@ -1678,6 +1726,29 @@ svn_dirent_canonicalize(const char *dire
return dst;
}
+svn_error_t *
+svn_dirent_canonicalize_safe(const char **canonical_dirent,
+ const char **non_canonical_result,
+ const char *dirent,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
+{
+ const char *const result = svn_dirent_canonicalize(dirent, result_pool);
+ if (!svn_dirent_is_canonical(result, scratch_pool))
+ {
+ if (non_canonical_result)
+ *non_canonical_result = result;
+
+ return svn_error_createf(
+ SVN_ERR_CANONICALIZATION_FAILED, NULL,
+ _("Could not canonicalize dirent '%s'"
+ " (the result '%s' is not canonical)"),
+ dirent, result);
+ }
+ *canonical_dirent = result;
+ return SVN_NO_ERROR;
+}
+
svn_boolean_t
svn_dirent_is_canonical(const char *dirent, apr_pool_t *scratch_pool)
{