Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function SetServer($host, $port=21, $reconnect=true) {
$this->SendMSG("Incorrect port syntax");
return FALSE;
} else {
$ip=@gethostbyname($host);
$ip=@get_host_by_name($host);
$dns=@gethostbyaddr($host);
if(!$ip) $ip=$host;
if(!$dns) $dns=$host;
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private static function get_wp_core(): array {
'value' => sprintf(
/* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
__( 'Unable to reach WordPress.org at %1$s: %2$s' ),
gethostbyname( 'wordpress.org' ),
get_host_by_name( 'wordpress.org' ),
$wp_dotorg->get_error_message()
),
'debug' => $wp_dotorg->get_error_message(),
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-site-health.php
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ public function get_test_dotorg_communication() {
sprintf(
/* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
__( 'Your site is unable to reach WordPress.org at %1$s, and returned the error: %2$s' ),
gethostbyname( 'api.wordpress.org' ),
get_host_by_name( 'api.wordpress.org' ),
$wp_dotorg->get_error_message()
)
)
Expand Down
31 changes: 29 additions & 2 deletions src/wp-includes/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,33 @@
return false;
}

function get_host_list_by_name( $host ) {
# Get DNS_A (IPv4) and DNS_AAAA (IPv6) records
$records = dns_get_record( $host, DNS_AAAA | DNS_A );

$ips = array();
foreach ( $records as $record ) {
if ( $record["type"] == "A" ) {

Check failure on line 545 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

String "A" does not require double quotes; use single quotes instead

Check failure on line 545 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Use Yoda Condition checks, you must.

Check failure on line 545 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

String "type" does not require double quotes; use single quotes instead
$ips[] = $record["ip"];

Check failure on line 546 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

String "ip" does not require double quotes; use single quotes instead
}
if ( $record["type"] == "AAAA" ) {

Check failure on line 548 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

String "AAAA" does not require double quotes; use single quotes instead

Check failure on line 548 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Use Yoda Condition checks, you must.

Check failure on line 548 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

String "type" does not require double quotes; use single quotes instead
$ips[] = $record["ipv6"];

Check failure on line 549 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

String "ipv6" does not require double quotes; use single quotes instead
}
}

return $ips;
}

function get_host_by_name( $host ) {
$ips = get_host_list_by_name( $host );

if ( $ips == false ) {

Check failure on line 559 in src/wp-includes/http.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Use Yoda Condition checks, you must.
return $host;
}

return $ips[0];
}

/**
* Validates a URL as safe for use in the HTTP API.
*
Expand Down Expand Up @@ -592,8 +619,8 @@
if ( preg_match( '#^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$#', $host ) ) {
$ip = $host;
} else {
$ip = gethostbyname( $host );
if ( $ip === $host ) { // Error condition for gethostbyname().
$ip = get_host_by_name( $host );
if ( $ip === $host ) { // Error condition for get_host_by_name().
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/http/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public function data_post_redirect_to_method_300() {
* @covers ::wp_remote_retrieve_body
*/
public function test_ip_url_with_host_header() {
$ip = gethostbyname( 'api.wordpress.org' );
$ip = get_host_by_name( 'api.wordpress.org' );
$url = 'http://' . $ip . '/core/tests/1.0/redirection.php?print-pass=1';
$args = array(
'headers' => array(
Expand Down
Loading