Skip to content

Commit

Permalink
Normalize behaviour of DNS function on Windows
Browse files Browse the repository at this point in the history
This is a follow-up on commit 4a438b4

Add some tests to hopefully not forget it next time
  • Loading branch information
Girgias committed Sep 12, 2020
1 parent 8446e28 commit c93a7b5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ext/standard/dns_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ PHP_FUNCTION(dns_check_record)
else if (!strcasecmp("NAPTR", rectype)) type = DNS_TYPE_NAPTR;
else if (!strcasecmp("A6", rectype)) type = DNS_TYPE_A6;
else {
php_error_docref(NULL, E_WARNING, "Type '%s' not supported", rectype);
RETURN_FALSE;
zend_argument_value_error(2, "must be a valid DNS record type");
RETURN_THROWS();
}
}

Expand Down Expand Up @@ -373,14 +373,13 @@ PHP_FUNCTION(dns_get_record)

if (!raw) {
if ((type_param & ~PHP_DNS_ALL) && (type_param != PHP_DNS_ANY)) {
php_error_docref(NULL, E_WARNING, "Type '%ld' not supported", type_param);
RETURN_FALSE;
zend_argument_value_error(2, "must be a DNS_* constant");
RETURN_THROWS();
}
} else {
if ((type_param < 1) || (type_param > 0xFFFF)) {
php_error_docref(NULL, E_WARNING,
"Numeric DNS record type must be between 1 and 65535, '%ld' given", type_param);
RETURN_FALSE;
zend_argument_value_error(2, "must be between 1 and 65535 when argument #5 ($raw) is true");
RETURN_THROWS();
}
}

Expand Down
19 changes: 19 additions & 0 deletions ext/standard/tests/network/dns_check_record_error_conditions.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
dns_check_record() error conditions
--FILE--
<?php
try {
dns_check_record('');
} catch (\ValueError $exception) {
echo $exception->getMessage() . "\n";
}
try {
// A random DNS Mode
dns_check_record('php.net', 15263480);
} catch (\ValueError $exception) {
echo $exception->getMessage() . "\n";
}
?>
--EXPECT--
dns_check_record(): Argument #1 ($hostname) cannot be empty
dns_check_record(): Argument #2 ($type) must be a valid DNS record type
31 changes: 31 additions & 0 deletions ext/standard/tests/network/dns_get_record_error_conditions.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
dns_get_record() error conditions
--FILE--
<?php
try {
// A random DNS Mode
dns_get_record('php.net', 15263480);
} catch (\ValueError $exception) {
echo $exception->getMessage() . "\n";
}
try {
// DNS Mode 0
$auth = [];
$additional = [];
dns_get_record('php.net', 0, $auth, $additional, true);
} catch (\ValueError $exception) {
echo $exception->getMessage() . "\n";
}
try {
// A random DNS Mode
$auth = [];
$additional = [];
dns_get_record('php.net', 15263480, $auth, $additional, true);
} catch (\ValueError $exception) {
echo $exception->getMessage() . "\n";
}
?>
--EXPECT--
dns_get_record(): Argument #2 ($type) must be a DNS_* constant
dns_get_record(): Argument #2 ($type) must be between 1 and 65535 when argument #5 ($raw) is true
dns_get_record(): Argument #2 ($type) must be between 1 and 65535 when argument #5 ($raw) is true

0 comments on commit c93a7b5

Please sign in to comment.