Skip to content

Fix bug #80565 #6492

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

BruceGitHub
Copy link

@BruceGitHub BruceGitHub commented Dec 6, 2020

This Pr point to resolve this bug
https://bugs.php.net/bug.php?id=80565

related for another version:
https://bugs.php.net/bug.php?id=74371
#3570

Originally created for PHP 7.1.3 but still present also in PHP 8/master.
https://3v4l.org/4Yaoj

Like the comment of the original PR, I followed the solution (for security aspects) of encoding the '<' and '>' instead of allowed. Because misuse of this function seems a more pragmatic approach.

The code of PHP 8 it's more readable ma still complex to manage. For this, I chose this approach.

Another solution may refactor the entire function. To allow the internal "state machine" to
know which context it's and change behavior based on this know-how for example.
This solution requires more effort.

To improve the readability I chose to use a macro I don't know if this choice follows the best practices
or the coding standard if not I can convert it to a static function.

For last if this PR it's appreciated, I can try to fix also the previous version like 7.x.

This it's my first PR for this repo so sorry if it does not respect the standard flow.

My apologies but It's been a long time since I wrote code in c. If need I try to improve the quality of code

@cmb69
Copy link
Member

cmb69 commented Dec 7, 2020

Thanks for the PR! Apparently, the test case is failing; can you please have a look?

@BruceGitHub
Copy link
Author

Thanks for the PR! Apparently, the test case is failing; can you please have a look?

Yes, but I not understood which it's the cause... I looking at che code to spot the problem.
The test that I pushed are green ...
So maybe some other related stuff...

@cmb69
Copy link
Member

cmb69 commented Dec 7, 2020

bugXXX.phpt is failing on AppVeyor as well as on Azure pipelines

@BruceGitHub
Copy link
Author

bugXXX.phpt is failing on AppVeyor as well as on Azure pipelines

Uh thanks! I try to fix

@carusogabriel
Copy link
Contributor

Is this a fix for PHP 8.0.X? If so, please rebase this PR on top of the PHP-8.0 branch, not the master :)

@cmb69
Copy link
Member

cmb69 commented Dec 7, 2020

strip_tags() strips < and > signs from attribute values since 5.2.7. However, it apparently never got it quite right. Considering that strip_tags() is doubtful per se, and that it is not rarely used to prevent XSS (although it is not meant for that purpose), I would be reluctant to fix it for stable versions (if at all).

@BruceGitHub
Copy link
Author

BruceGitHub commented Dec 7, 2020

strip_tags() strips < and > signs from attribute values since 5.2.7. However, it apparently never got it quite right. Considering that strip_tags() is doubtful per se, and that it is not rarely used to prevent XSS (although it is not meant for that purpose), I would be reluctant to fix it for stable versions (if at all).

Mm ok so I think to close PR ? Or not ?

@cmb69
Copy link
Member

cmb69 commented Dec 7, 2020

If you find a good solution, in my opionion, it's fine for "master". :)

@BruceGitHub
Copy link
Author

The pipe is passed now. But I found a strange behavior. Soon I push a test...

@BruceGitHub
Copy link
Author

BruceGitHub commented Dec 9, 2020

btw this test don't pass

--TEST--
Bug #XXXXX: strip_tags strip >< in attributes with allow tag
--FILE--
<?php

echo strip_tags('<ta alt="abc< " >', '<ta>').\PHP_EOL;
echo strip_tags('<ta alt="abc> " >', '<ta>').\PHP_EOL;
echo strip_tags('<t y="1< 2< 3< 4< 5< 6< 7< 8< 9< 10<" />', '<t>').\PHP_EOL;
?>
--EXPECT--
<ta alt="abc&lt; " >
<ta alt="abc&gt; " >
<t y="1&lt; 2&lt; 3&lt; 4&lt; 5&lt; 6&lt; 7&lt; 8&lt; 9&lt; 10&lt;" />

The problems it's with the original buffer allocated with the size of the initial input. This function it's written to decrease the size of the buffer
with this change instead the size increase.

I worked a lot to solve.

First, I tried with a solution like the first PR (but realloc not work with zend_string or I didn't succeed).
For me the best solutions it's put in signature zend_string * then zend_string_extends when we need to resize the buffer
then remove char *.
But I deal with a memory leak.
These days I try to solve...

@BruceGitHub BruceGitHub marked this pull request as draft December 13, 2020 13:16
@BruceGitHub
Copy link
Author

Ole! Now all green!

@BruceGitHub BruceGitHub marked this pull request as ready for review December 21, 2020 00:24
@BruceGitHub BruceGitHub changed the title Adds test and fix to bug 74371 but for php8 Adds test and fix to bug 80565 but for php8 Dec 30, 2020
@BruceGitHub BruceGitHub changed the title Adds test and fix to bug 80565 but for php8 Adds test and fix to bug 80565 Dec 30, 2020
@BruceGitHub BruceGitHub changed the title Adds test and fix to bug 80565 Fix bug #80565 Dec 30, 2020
@BruceGitHub
Copy link
Author

I must resolve conflicts ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants