summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-07-15 15:10:28 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-07-15 15:10:40 +0200
commit2053329b1a04cfb2b503f3ea9b19d2fdd900987e (patch)
tree102810c738ef978b788f749f805e23f917d2c96a
parente8430b592f977a8aaccf13f3213ff0d987388d13 (diff)
parent2c57378bd3725b82ac1217b636e21e3006b5ca03 (diff)
downloadphp-git-2053329b1a04cfb2b503f3ea9b19d2fdd900987e.tar.gz
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix bug #78008: dns_check_record() always return true on Alpine
-rw-r--r--NEWS2
-rw-r--r--ext/standard/dns.c32
2 files changed, 16 insertions, 18 deletions
diff --git a/NEWS b/NEWS
index 3c688cbaa3..5f1ac6ceb2 100644
--- a/NEWS
+++ b/NEWS
@@ -47,6 +47,8 @@ PHP NEWS
- Standard:
. Fixed bug #70362 (Can't copy() large 'data://' with open_basedir). (cmb)
+ . Fixed bug #78008 (dns_check_record() always return true on Alpine).
+ (Andy Postnikov)
09 Jul 2020, PHP 7.4.8
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
index 9c0faf3cb2..3c9ce269c4 100644
--- a/ext/standard/dns.c
+++ b/ext/standard/dns.c
@@ -362,10 +362,8 @@ static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
Check DNS records corresponding to a given Internet host name or IP address */
PHP_FUNCTION(dns_check_record)
{
-#ifndef MAXPACKET
-#define MAXPACKET 8192 /* max packet size used internally by BIND */
-#endif
- u_char ans[MAXPACKET];
+ HEADER *hp;
+ querybuf answer;
char *hostname, *rectype = NULL;
size_t hostname_len, rectype_len = 0;
int type = DNS_T_MX, i;
@@ -423,14 +421,14 @@ PHP_FUNCTION(dns_check_record)
res_init();
#endif
- RETVAL_TRUE;
- i = php_dns_search(handle, hostname, C_IN, type, ans, sizeof(ans));
+ i = php_dns_search(handle, hostname, C_IN, type, answer.qb2, sizeof answer);
+ php_dns_free_handle(handle);
if (i < 0) {
- RETVAL_FALSE;
+ RETURN_FALSE;
}
-
- php_dns_free_handle(handle);
+ hp = (HEADER *)&answer;
+ RETURN_BOOL(ntohs(hp->ancount) != 0);
}
/* }}} */
@@ -1050,7 +1048,7 @@ PHP_FUNCTION(dns_get_mx)
zval *mx_list, *weight_list = NULL;
int count, qdc;
u_short type, weight;
- u_char ans[MAXPACKET];
+ querybuf answer;
char buf[MAXHOSTNAMELEN];
HEADER *hp;
u_char *cp, *end;
@@ -1097,16 +1095,14 @@ PHP_FUNCTION(dns_get_mx)
res_init();
#endif
- i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, (u_char *)&ans, sizeof(ans));
+ i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, answer.qb2, sizeof answer);
if (i < 0) {
+ php_dns_free_handle(handle);
RETURN_FALSE;
}
- if (i > (int)sizeof(ans)) {
- i = sizeof(ans);
- }
- hp = (HEADER *)&ans;
- cp = (u_char *)&ans + HFIXEDSZ;
- end = (u_char *)&ans +i;
+ hp = (HEADER *)&answer;
+ cp = answer.qb2 + HFIXEDSZ;
+ end = answer.qb2 + i;
for (qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) {
if ((i = dn_skipname(cp, end)) < 0 ) {
php_dns_free_handle(handle);
@@ -1128,7 +1124,7 @@ PHP_FUNCTION(dns_get_mx)
continue;
}
GETSHORT(weight, cp);
- if ((i = dn_expand(ans, end, cp, buf, sizeof(buf)-1)) < 0) {
+ if ((i = dn_expand(answer.qb2, end, cp, buf, sizeof(buf)-1)) < 0) {
php_dns_free_handle(handle);
RETURN_FALSE;
}