Skip to content

Commit

Permalink
On the 'apply-processor' branch: sync with trunk@r1922653.
Browse files Browse the repository at this point in the history
  • Loading branch information
rinrab committed Dec 23, 2024
2 parents 8fcdb0c + 9a22948 commit 3b95fc7
Show file tree
Hide file tree
Showing 18 changed files with 615 additions and 264 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,16 @@ jobs:
working-directory: out
run: ctest --output-on-failure --verbose -C Release --parallel 16

- name: Rerun failed tests
if: ${{ matrix.run_tests && failure() && steps.run_all_tests.conclusion == 'failure' }}
- name: Test shelf2
if: matrix.run_tests
working-directory: out
env:
SVN_EXPERIMENTAL_COMMANDS: shelf2
run: ctest -R shelf2 --verbose -C Release

- name: Test shelf3
if: matrix.run_tests
working-directory: out
run: ctest --output-on-failure --verbose -C Release --rerun-failed
env:
SVN_EXPERIMENTAL_COMMANDS: shelf3
run: ctest -R shelf3 --verbose -C Release
2 changes: 1 addition & 1 deletion subversion/bindings/swig/include/svn_types.swg
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE self)
%typemap(ret) svn_error_t *
{
if (TYPE(*svn_presult) == T_ARRAY) {
switch (rb_array_len(*svn_presult)) {
switch (RARRAY_LEN(*svn_presult)) {
case 0:
*svn_presult = Qnil;
break;
Expand Down
2 changes: 1 addition & 1 deletion subversion/include/private/svn_client_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ svn_client__get_diff_writer_svn(
svn_boolean_t ignore_content_type,
svn_boolean_t ignore_properties,
svn_boolean_t properties_only,
svn_boolean_t pretty_print_mergeinfo,
svn_boolean_t use_git_diff_format,
svn_boolean_t pretty_print_mergeinfo,
const char *header_encoding,
svn_stream_t *outstream,
svn_stream_t *errstream,
Expand Down
8 changes: 8 additions & 0 deletions subversion/include/private/svn_repos_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ svn_repos__get_dump_editor(const svn_delta_editor_t **editor,
const char *update_anchor_relpath,
apr_pool_t *pool);

/* Validate that the given PATH is a valid pathname that can be stored in
* a Subversion repository, according to the name constraints used by the
* svn_repos_* layer.
*/
svn_error_t *
svn_repos__validate_new_path(const char *path,
apr_pool_t *scratch_pool);

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
18 changes: 18 additions & 0 deletions subversion/include/svn_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "svn_types.h"
#include "svn_string.h"
#include "svn_io.h" /* for svn_stream_t */

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -191,6 +192,23 @@ void
svn_xml_free_parser(svn_xml_parser_t *svn_parser);


/** Create a stream that wraps the XML parser described at @a parser.
*
* The stream produced will implement 'write' and 'close' methods. It
* will push the data to the parser on write operation, and flush it on
* close.
*
* This stream can be used as a generic writable stream, so the callers
* may pipe any data there, for example, using the svn_stream_copy3
* function, in case of a file source.
*
* @since New in 1.15.
*/
svn_stream_t *
svn_xml_make_parse_stream(svn_xml_parser_t *parser,
apr_pool_t *result_pool);


/** Push @a len bytes of xml data in @a buf at @a svn_parser.
*
* If this is the final push, @a is_final must be set.
Expand Down
3 changes: 1 addition & 2 deletions subversion/libsvn_repos/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ add_file_or_directory(const char *path,
svn_boolean_t was_copied = FALSE;
const char *full_path, *canonicalized_path;

/* Reject paths which contain control characters (related to issue #4340). */
SVN_ERR(svn_path_check_valid(path, pool));
SVN_ERR(svn_repos__validate_new_path(path, pool));

SVN_ERR(svn_relpath_canonicalize_safe(&canonicalized_path, NULL, path,
pool, pool));
Expand Down
10 changes: 10 additions & 0 deletions subversion/libsvn_repos/repos.c
Original file line number Diff line number Diff line change
Expand Up @@ -2092,3 +2092,13 @@ svn_repos__fs_type(const char **fs_type,
svn_dirent_join(repos_path, SVN_REPOS__DB_DIR, pool),
pool);
}

svn_error_t *
svn_repos__validate_new_path(const char *path,
apr_pool_t *scratch_pool)
{
/* Reject paths which contain control characters (related to issue #4340). */
SVN_ERR(svn_path_check_valid(path, scratch_pool));

return SVN_NO_ERROR;
}
247 changes: 0 additions & 247 deletions subversion/libsvn_subr/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#include "svn_pools.h"
#include "svn_xml.h"
#include "svn_error.h"
#include "svn_ctype.h"

#include "private/svn_utf_private.h"
#include "private/svn_subr_private.h"

#ifdef SVN_HAVE_OLD_EXPAT
Expand Down Expand Up @@ -98,251 +96,6 @@ struct svn_xml_parser_t

};


/*** XML character validation ***/

svn_boolean_t
svn_xml_is_xml_safe(const char *data, apr_size_t len)
{
const char *end = data + len;
const char *p;

if (! svn_utf__is_valid(data, len))
return FALSE;

for (p = data; p < end; p++)
{
unsigned char c = *p;

if (svn_ctype_iscntrl(c))
{
if ((c != SVN_CTYPE_ASCII_TAB)
&& (c != SVN_CTYPE_ASCII_LINEFEED)
&& (c != SVN_CTYPE_ASCII_CARRIAGERETURN)
&& (c != SVN_CTYPE_ASCII_DELETE))
return FALSE;
}
}
return TRUE;
}





/*** XML escaping. ***/

/* ### ...?
*
* If *OUTSTR is @c NULL, set *OUTSTR to a new stringbuf allocated
* in POOL, else append to the existing stringbuf there.
*/
static void
xml_escape_cdata(svn_stringbuf_t **outstr,
const char *data,
apr_size_t len,
apr_pool_t *pool)
{
const char *end = data + len;
const char *p = data, *q;

if (*outstr == NULL)
*outstr = svn_stringbuf_create_empty(pool);

while (1)
{
/* Find a character which needs to be quoted and append bytes up
to that point. Strictly speaking, '>' only needs to be
quoted if it follows "]]", but it's easier to quote it all
the time.
So, why are we escaping '\r' here? Well, according to the
XML spec, '\r\n' gets converted to '\n' during XML parsing.
Also, any '\r' not followed by '\n' is converted to '\n'. By
golly, if we say we want to escape a '\r', we want to make
sure it remains a '\r'! */
q = p;
while (q < end && *q != '&' && *q != '<' && *q != '>' && *q != '\r')
q++;
svn_stringbuf_appendbytes(*outstr, p, q - p);

/* We may already be a winner. */
if (q == end)
break;

/* Append the entity reference for the character. */
if (*q == '&')
svn_stringbuf_appendcstr(*outstr, "&amp;");
else if (*q == '<')
svn_stringbuf_appendcstr(*outstr, "&lt;");
else if (*q == '>')
svn_stringbuf_appendcstr(*outstr, "&gt;");
else if (*q == '\r')
svn_stringbuf_appendcstr(*outstr, "&#13;");

p = q + 1;
}
}

/* Essentially the same as xml_escape_cdata, with the addition of
whitespace and quote characters. */
static void
xml_escape_attr(svn_stringbuf_t **outstr,
const char *data,
apr_size_t len,
apr_pool_t *pool)
{
const char *end = data + len;
const char *p = data, *q;

if (*outstr == NULL)
*outstr = svn_stringbuf_create_ensure(len, pool);

while (1)
{
/* Find a character which needs to be quoted and append bytes up
to that point. */
q = p;
while (q < end && *q != '&' && *q != '<' && *q != '>'
&& *q != '"' && *q != '\'' && *q != '\r'
&& *q != '\n' && *q != '\t')
q++;
svn_stringbuf_appendbytes(*outstr, p, q - p);

/* We may already be a winner. */
if (q == end)
break;

/* Append the entity reference for the character. */
if (*q == '&')
svn_stringbuf_appendcstr(*outstr, "&amp;");
else if (*q == '<')
svn_stringbuf_appendcstr(*outstr, "&lt;");
else if (*q == '>')
svn_stringbuf_appendcstr(*outstr, "&gt;");
else if (*q == '"')
svn_stringbuf_appendcstr(*outstr, "&quot;");
else if (*q == '\'')
svn_stringbuf_appendcstr(*outstr, "&apos;");
else if (*q == '\r')
svn_stringbuf_appendcstr(*outstr, "&#13;");
else if (*q == '\n')
svn_stringbuf_appendcstr(*outstr, "&#10;");
else if (*q == '\t')
svn_stringbuf_appendcstr(*outstr, "&#9;");

p = q + 1;
}
}


void
svn_xml_escape_cdata_stringbuf(svn_stringbuf_t **outstr,
const svn_stringbuf_t *string,
apr_pool_t *pool)
{
xml_escape_cdata(outstr, string->data, string->len, pool);
}


void
svn_xml_escape_cdata_string(svn_stringbuf_t **outstr,
const svn_string_t *string,
apr_pool_t *pool)
{
xml_escape_cdata(outstr, string->data, string->len, pool);
}


void
svn_xml_escape_cdata_cstring(svn_stringbuf_t **outstr,
const char *string,
apr_pool_t *pool)
{
xml_escape_cdata(outstr, string, (apr_size_t) strlen(string), pool);
}


void
svn_xml_escape_attr_stringbuf(svn_stringbuf_t **outstr,
const svn_stringbuf_t *string,
apr_pool_t *pool)
{
xml_escape_attr(outstr, string->data, string->len, pool);
}


void
svn_xml_escape_attr_string(svn_stringbuf_t **outstr,
const svn_string_t *string,
apr_pool_t *pool)
{
xml_escape_attr(outstr, string->data, string->len, pool);
}


void
svn_xml_escape_attr_cstring(svn_stringbuf_t **outstr,
const char *string,
apr_pool_t *pool)
{
xml_escape_attr(outstr, string, (apr_size_t) strlen(string), pool);
}


const char *
svn_xml_fuzzy_escape(const char *string, apr_pool_t *pool)
{
const char *end = string + strlen(string);
const char *p = string, *q;
svn_stringbuf_t *outstr;
char escaped_char[6]; /* ? \ u u u \0 */

for (q = p; q < end; q++)
{
if (svn_ctype_iscntrl(*q)
&& ! ((*q == '\n') || (*q == '\r') || (*q == '\t')))
break;
}

/* Return original string if no unsafe characters found. */
if (q == end)
return string;

outstr = svn_stringbuf_create_empty(pool);
while (1)
{
q = p;

/* Traverse till either unsafe character or eos. */
while ((q < end)
&& ((! svn_ctype_iscntrl(*q))
|| (*q == '\n') || (*q == '\r') || (*q == '\t')))
q++;

/* copy chunk before marker */
svn_stringbuf_appendbytes(outstr, p, q - p);

if (q == end)
break;

/* Append an escaped version of the unsafe character.
### This format was chosen for consistency with
### svn_utf__cstring_from_utf8_fuzzy(). The two functions
### should probably share code, even though they escape
### different characters.
*/
apr_snprintf(escaped_char, sizeof(escaped_char), "?\\%03u",
(unsigned char) *q);
svn_stringbuf_appendcstr(outstr, escaped_char);

p = q + 1;
}

return outstr->data;
}


/*** Map from the Expat callback types to the SVN XML types. ***/

Expand Down
Loading

0 comments on commit 3b95fc7

Please sign in to comment.