Skip to content

Commit

Permalink
testescape: missing ';' in entity escaping.
Browse files Browse the repository at this point in the history
apr_escape_entity(): Don't truncate the final ';' in hex entities.

apr_snprintf() takes the buffer size (include NUL), and can by used with
NULL/zero-size buffer to determine the output length.


Merges r1916332, r1916390 from ^/apr/apr/trunk


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1916392 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ylavic committed Mar 18, 2024
1 parent b97ebdf commit 059c695
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions encoding/apr_escape.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ APR_DECLARE(apr_status_t) apr_escape_entity(char *escaped, const char *str,
found = 1;
}
else if (toasc && !apr_isascii(c)) {
int offset = apr_snprintf((char *) d, 6, "&#%3.3d;", c);
int offset = apr_snprintf((char *) d, 7, "&#%3.3d;", c);
size += offset;
d += offset;
found = 1;
Expand Down Expand Up @@ -613,8 +613,7 @@ APR_DECLARE(apr_status_t) apr_escape_entity(char *escaped, const char *str,
found = 1;
}
else if (toasc && !apr_isascii(c)) {
char buf[8];
size += apr_snprintf(buf, 6, "&#%3.3d;", c);
size += apr_snprintf(NULL, 0, "&#%3.3d;", c);
found = 1;
}
else {
Expand Down
2 changes: 1 addition & 1 deletion test/testescape.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static void test_escape(abts_case *tc, void *data)
ABTS_PTR_EQUAL(tc, src, dest);

src = "\xFF<>&\'\"Hello World";
target = "&#255&lt;&gt;&amp;'&quot;Hello World";
target = "&#255;&lt;&gt;&amp;'&quot;Hello World";
dest = apr_pescape_entity(pool, src, 1);
ABTS_STR_EQUAL(tc, target, dest);
apr_escape_entity(NULL, src, APR_ESCAPE_STRING, 1, &len);
Expand Down

0 comments on commit 059c695

Please sign in to comment.