summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2020-09-12 18:41:25 +0200
committerGeorge Peter Banyard <girgias@php.net>2020-09-12 18:41:25 +0200
commitc93a7b50b46888bcb0c57a2dbac78b0f31637949 (patch)
treeb7b228aca4bafb26c7c48c51bea274cc954a0d5b
parent8446e2827585c37d0739f8d44fa8d359cbbb6551 (diff)
downloadphp-git-c93a7b50b46888bcb0c57a2dbac78b0f31637949.tar.gz
Normalize behaviour of DNS function on Windows
This is a follow-up on commit 4a438b44694d4caf86d8e57266ed2fc2f4ae6213 Add some tests to hopefully not forget it next time
-rw-r--r--ext/standard/dns_win32.c13
-rw-r--r--ext/standard/tests/network/dns_check_record_error_conditions.phpt19
-rw-r--r--ext/standard/tests/network/dns_get_record_error_conditions.phpt31
3 files changed, 56 insertions, 7 deletions
diff --git a/ext/standard/dns_win32.c b/ext/standard/dns_win32.c
index 838a40c94e..afeab23a08 100644
--- a/ext/standard/dns_win32.c
+++ b/ext/standard/dns_win32.c
@@ -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();
}
}
@@ -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();
}
}
diff --git a/ext/standard/tests/network/dns_check_record_error_conditions.phpt b/ext/standard/tests/network/dns_check_record_error_conditions.phpt
new file mode 100644
index 0000000000..dae0bfb375
--- /dev/null
+++ b/ext/standard/tests/network/dns_check_record_error_conditions.phpt
@@ -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
diff --git a/ext/standard/tests/network/dns_get_record_error_conditions.phpt b/ext/standard/tests/network/dns_get_record_error_conditions.phpt
new file mode 100644
index 0000000000..6506aca410
--- /dev/null
+++ b/ext/standard/tests/network/dns_get_record_error_conditions.phpt
@@ -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