Skip to content

Commit c93a7b5

Browse files
committed
Normalize behaviour of DNS function on Windows
This is a follow-up on commit 4a438b4 Add some tests to hopefully not forget it next time
1 parent 8446e28 commit c93a7b5

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

ext/standard/dns_win32.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ PHP_FUNCTION(dns_check_record)
124124
else if (!strcasecmp("NAPTR", rectype)) type = DNS_TYPE_NAPTR;
125125
else if (!strcasecmp("A6", rectype)) type = DNS_TYPE_A6;
126126
else {
127-
php_error_docref(NULL, E_WARNING, "Type '%s' not supported", rectype);
128-
RETURN_FALSE;
127+
zend_argument_value_error(2, "must be a valid DNS record type");
128+
RETURN_THROWS();
129129
}
130130
}
131131

@@ -373,14 +373,13 @@ PHP_FUNCTION(dns_get_record)
373373

374374
if (!raw) {
375375
if ((type_param & ~PHP_DNS_ALL) && (type_param != PHP_DNS_ANY)) {
376-
php_error_docref(NULL, E_WARNING, "Type '%ld' not supported", type_param);
377-
RETURN_FALSE;
376+
zend_argument_value_error(2, "must be a DNS_* constant");
377+
RETURN_THROWS();
378378
}
379379
} else {
380380
if ((type_param < 1) || (type_param > 0xFFFF)) {
381-
php_error_docref(NULL, E_WARNING,
382-
"Numeric DNS record type must be between 1 and 65535, '%ld' given", type_param);
383-
RETURN_FALSE;
381+
zend_argument_value_error(2, "must be between 1 and 65535 when argument #5 ($raw) is true");
382+
RETURN_THROWS();
384383
}
385384
}
386385

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
dns_check_record() error conditions
3+
--FILE--
4+
<?php
5+
try {
6+
dns_check_record('');
7+
} catch (\ValueError $exception) {
8+
echo $exception->getMessage() . "\n";
9+
}
10+
try {
11+
// A random DNS Mode
12+
dns_check_record('php.net', 15263480);
13+
} catch (\ValueError $exception) {
14+
echo $exception->getMessage() . "\n";
15+
}
16+
?>
17+
--EXPECT--
18+
dns_check_record(): Argument #1 ($hostname) cannot be empty
19+
dns_check_record(): Argument #2 ($type) must be a valid DNS record type
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
dns_get_record() error conditions
3+
--FILE--
4+
<?php
5+
try {
6+
// A random DNS Mode
7+
dns_get_record('php.net', 15263480);
8+
} catch (\ValueError $exception) {
9+
echo $exception->getMessage() . "\n";
10+
}
11+
try {
12+
// DNS Mode 0
13+
$auth = [];
14+
$additional = [];
15+
dns_get_record('php.net', 0, $auth, $additional, true);
16+
} catch (\ValueError $exception) {
17+
echo $exception->getMessage() . "\n";
18+
}
19+
try {
20+
// A random DNS Mode
21+
$auth = [];
22+
$additional = [];
23+
dns_get_record('php.net', 15263480, $auth, $additional, true);
24+
} catch (\ValueError $exception) {
25+
echo $exception->getMessage() . "\n";
26+
}
27+
?>
28+
--EXPECT--
29+
dns_get_record(): Argument #2 ($type) must be a DNS_* constant
30+
dns_get_record(): Argument #2 ($type) must be between 1 and 65535 when argument #5 ($raw) is true
31+
dns_get_record(): Argument #2 ($type) must be between 1 and 65535 when argument #5 ($raw) is true

0 commit comments

Comments
 (0)