New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*) core: make ap_escape_quotes() work correctly on strings #298
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,6 +357,7 @@ Release | |
/test/sni | ||
/test/httpdunit | ||
/test/httpdunit.cases | ||
/check/ | ||
|
||
# /test/unit/ | ||
/test/unit/*.tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*) core: make ap_escape_quotes() work correctly on strings | ||
with more than MAX_INT/2 characters, counting quotes double. | ||
Credit to <generalbugs@zippenhop.com> for finding this. | ||
[Stefan Eissing] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2615,7 +2615,7 @@ AP_DECLARE(void) ap_content_type_tolower(char *str) | |
*/ | ||
AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring) | ||
{ | ||
int newlen = 0; | ||
apr_ssize_t extra = 0; | ||
const char *inchr = instring; | ||
char *outchr, *outstring; | ||
|
||
|
@@ -2624,21 +2624,24 @@ AP_DECLARE(char *) ap_escape_quotes(apr_pool_t *p, const char *instring) | |
* string up by an extra byte each time we find an unescaped ". | ||
*/ | ||
while (*inchr != '\0') { | ||
newlen++; | ||
if (*inchr == '"') { | ||
newlen++; | ||
extra++; | ||
} | ||
/* | ||
* If we find a slosh, and it's not the last byte in the string, | ||
* it's escaping something - advance past both bytes. | ||
*/ | ||
else if ((*inchr == '\\') && (inchr[1] != '\0')) { | ||
inchr++; | ||
newlen++; | ||
} | ||
inchr++; | ||
} | ||
outstring = apr_palloc(p, newlen + 1); | ||
|
||
if (!extra) { | ||
return apr_pstrdup(p, instring); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe apr_pmemdup(), as we can easily compute the length, as done below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion. |
||
outstring = apr_palloc(p, (inchr - instring) + extra + 1); | ||
inchr = instring; | ||
outchr = outstring; | ||
/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Why apr_ssize_t and not apr_size_t?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra
is used in aptrdiff_t
expression below, which is signed.apr_ssize_t
isptrdiff_t
on all but the most ancients of platforms.But is it correct to use? The question is, does it deal correctly with strings that are longer than ptrdiff_t can hold (lets call this PTRDIFF_MAX)?
instring
that is longer than PTRDIFF_MAX: this would mean trouble as(inchr - instring)
in the palloc expression would overflow. Which is undefined behaviour in C. C defines that you can substract pointers intothe same array to get a number. So, maybe we can ignore that one.
instring
that is almost as long as PTRDIFF_MAX with enough quote characters that the resulting length is larger than PTRDIFF_MAX. This is currently not checked.I think we need a check that the expression
(inchr - instring) + extra + 1
did not overflow, e.g. became < 0, to be totally safe. And for this, we need to calculdate inapr_ssize_t
, I guess.What do you think?