Skip to content
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

Bug #63162 - parse_url does not matches password component #206

Closed
wants to merge 3 commits into from
Closed

Bug #63162 - parse_url does not matches password component #206

wants to merge 3 commits into from

Conversation

husman
Copy link

@husman husman commented Sep 27, 2012

Here is a fix for Bug #63162 - parse_url does not matches password component. Here is a link to the original bug post:

https://bugs.php.net/bug.php?id=63162

The source of error is in the function php_url_parse_ex, which is in the file: ext/standard/url.c.

The function starts with a pointer to the beginning of the input string and scans up to the memory location of the first occurrence of the character ';'. If the input string is: //user:pass@host, then the if condition within the the "parse scheme" section is met due to the fact that / is non-alpha, non-digit, and is not in the set <+, ., ->, therefore, the goto parse_port is triggered. parse_port begins at an offset one (+1) greater than the location of ';'. However, this region is expecting numeric characters for the next 6 digits so it loops 6 times with no hit, due to the fact that we do not have a numeric value after ';'. The next "if" condition is also not met due to the fact that pp was never incremented in the while loop above. therefore, we hit the else-if and else. The first else-if is not meant due to the fact that our string has not yet terminated. Finally, the second else if contains the fix to test if we made a bad assumption that the port is expected.

Here are the results/output before the fix:

// input = http://user:pass@host
Array
(
[scheme] => http
[host] => host
[user] => user
[pass] => pass
)

// input = //user:pass@host
Array
(
[path] => //user:pass@host
)

// input = //user@host
Array
(
[host] => host
[user] => user
)

Here are the results/output after the fix:

// input = http://user:pass@host
Array
(
[scheme] => http
[host] => host
[user] => user
[pass] => pass
)

// input = //user:pass@host
Array
(
[host] => host
[user] => user
[pass] => pass
)

// input = //user@host
Array
(
[host] => host
[user] => user
)

I hope this helps. Thanks!

@laruence
Copy link
Member

A test script(.phpt) is needed, thanks

@husman
Copy link
Author

husman commented Sep 27, 2012

Hey Laruence, I just committed bug63162.phpt to tests/output/bug63162.phpt. Thanks for the notice and sorry for the delay.

@php-pulls
Copy link

Comment on behalf of stas at php.net:

merged

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

Successfully merging this pull request may close these issues.

3 participants