From e7577d57cdae2e702961455bbe25ff02452f2ea0 Mon Sep 17 00:00:00 2001 From: Scott MacVicar Date: Thu, 10 May 2007 13:16:54 +0000 Subject: [PATCH] Fixed bug #41347 (checkdnsrr() segfaults on empty hostname). --- NEWS | 1 + ext/standard/dns.c | 12 ++++++++++++ ext/standard/tests/network/bug41347.phpt | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 ext/standard/tests/network/bug41347.phpt diff --git a/NEWS b/NEWS index 5801c863f50..5d9b9b169a2 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ PHP NEWS (Ilia) - Fixed altering $this via argument named "this". (Dmitry) - Fixed PHP CLI to use the php.ini from the binary location. (Hannes) +- Fixed bug #41347 (checkdnsrr() segfaults on empty hostname). (Scott) - Fixed bug #41326 (Writing empty tags with Xmlwriter::WriteElement[ns]) (Pierre) - Fixed bug #41321 (downgrade read errors in getimagesize() to E_NOTICE). diff --git a/ext/standard/dns.c b/ext/standard/dns.c index fd408061678..4e4242458b4 100644 --- a/ext/standard/dns.c +++ b/ext/standard/dns.c @@ -264,6 +264,12 @@ PHP_FUNCTION(dns_check_record) } type = T_MX; convert_to_string_ex(arg1); + + if (Z_STRLEN_PP(arg1) == 0) + { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Host cannot be empty"); + RETURN_FALSE; + } break; case 2: @@ -273,6 +279,12 @@ PHP_FUNCTION(dns_check_record) convert_to_string_ex(arg1); convert_to_string_ex(arg2); + if (Z_STRLEN_PP(arg1) == 0 || Z_STRLEN_PP(arg2) == 0) + { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Host and type cannot be empty"); + RETURN_FALSE; + } + if (!strcasecmp("A", Z_STRVAL_PP(arg2))) type = T_A; else if (!strcasecmp("NS", Z_STRVAL_PP(arg2))) type = DNS_T_NS; else if (!strcasecmp("MX", Z_STRVAL_PP(arg2))) type = DNS_T_MX; diff --git a/ext/standard/tests/network/bug41347.phpt b/ext/standard/tests/network/bug41347.phpt new file mode 100644 index 00000000000..ef93a202bc5 --- /dev/null +++ b/ext/standard/tests/network/bug41347.phpt @@ -0,0 +1,19 @@ +--TEST-- +dns_check_record() segfault with empty host +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: dns_check_record(): Host cannot be empty in %s on line %d +bool(false) + +Warning: dns_check_record(): Host and type cannot be empty in %s on line %d +bool(false)