-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Be consistent in clearing out in php_iconv_string() #3037
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
Conversation
@tpunt Did you want me to make that PR as well? Or amend this one? |
Depending on which version of libiconv you're using, php_iconv_string() doesn't always null out *out as part of its initialization. This patch makes that behavior invariant. Submitted upstream as php/php-src#3037 where it's approved and waiting a merge. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Depending on which version of libiconv you're using, php_iconv_string() doesn't always null out *out as part of its initialization. This patch makes that behavior invariant. Submitted upstream as php/php-src#3037 where it's approved and waiting a merge. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Since removing the superfluous buffer freeing logic would also fix this problem, I'd say just amend this PR with those changes too. |
7d3303a
to
8b6882d
Compare
Done. Ran |
Depending on which version of libiconv you're using, php_iconv_string() doesn't always null out *out as part of its initialization. This patch makes that behavior invariant. Submitted upstream as php/php-src#3037 where it's approved and waiting a merge. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
@tpunt Are these being affected as a side-effect?
Haven't read the test cases so I'm not sure what the scenarios are... |
Ah, my mistake, it appears the |
Also, don't bother checking returned point in error case since it will always be NULL (and not require free()ing, obviously).
8b6882d
to
31e53f0
Compare
Just trying to see what Travis finds that doesn't turn up locally if we do as you suggest and always free on error. |
@tpunt Well, I took your suggestion all the way and the build didn't have any Failed Tests. I separated the commits to the original/minimal fix plus the more complete fixes. You can merge just the first or both, as you see fit. |
Depending on which version of libiconv you're using, php_iconv_string() doesn't always null out *out as part of its initialization. This patch makes that behavior invariant. Submitted upstream as php/php-src#3037 where it's approved and waiting a merge. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
@tpunt Let me know if you need anything else, otherwise I'm assuming we're good to go. |
@pprindeville This looks fine to me. I don't have the appropriate karma to merge your PR, though. Perhaps @nikic could merge this instead. |
@tpunt Thanks, understood. |
iconv_close(cd); | ||
|
||
if (result == (size_t)(-1)) { | ||
zend_string_free(out_buf); |
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.
This will cause a use-after-free of out_buf
in the code below. If we free out_buf
here, then the breaks in the switch below need to be changed to returns. (As is the case for PHP_ICONV_ERR_UNKNOWN, which was the only freeing case previously.)
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.
Okay, since it's not clear what the semantic is for "return an error but leave a partially populated buffer" I suggest just going with the first commit.
There is one use of No idea whether or not that's really the case, or if this is just an oversight. |
I'd say merge the |
Given your previous comment, maybe just go with the first commit everywhere? |
Should I prep separate PR's for 7.1 and 7.2 or will someone else cherry-pick them? |
Okay, let's go with the conservative variant... I've merged the first commit as aad76a9 into 7.1+. |
@nikic Do I need to prepare PR's for 7.2 and master or is that already done? |
@pprindeville This is already done. We always apply changes to the lowest branch and then merge upward. |
Okay, thanks. |
JFTR: this fixed bug 75867. |
Depending on which version of libiconv you're using, php_iconv_string() doesn't always null out *out as part of its initialization. This patch makes that behavior invariant. Submitted upstream as php/php-src#3037 where it's approved and waiting a merge. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Tested by @MikePetullo here