Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] check for empty host when calling checkdnsrr() #22109

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

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch to empty native function to check emptiness
Switch to `empty` because depending on the PHP version, substr returns '' or false
  • Loading branch information
apetitpa committed Mar 27, 2017
commit 756f9ce48a57b281b7892eb8a40b6230fba318dc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function validate($value, Constraint $constraint)
*/
private function checkMX($host)
{
return '' !== $host && checkdnsrr($host, 'MX');
return !empty($host) && checkdnsrr($host, 'MX');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid empty :) We expect a string, and only a empty string ($host === '') should not be passed to checkdnsrr.

Copy link
Author

@apetitpa apetitpa Mar 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know but substr($value, strrpos($value, '@') + 1) with $value = 'foo@bar.fr@' returns "" with PHP 7.* and false with PHP 5.6. So only checking for string emptiness is not enough.

Copy link
Contributor

@ro0NL ro0NL Mar 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cast the substring result above. $host = (string) ...;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done, thank you

}

/**
Expand All @@ -130,6 +130,6 @@ private function checkMX($host)
*/
private function checkHost($host)
{
return '' !== $host && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
return !empty($host) && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.