Skip to content

Commit 2053329

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix bug #78008: dns_check_record() always return true on Alpine
2 parents e8430b5 + 2c57378 commit 2053329

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ PHP NEWS
4747

4848
- Standard:
4949
. Fixed bug #70362 (Can't copy() large 'data://' with open_basedir). (cmb)
50+
. Fixed bug #78008 (dns_check_record() always return true on Alpine).
51+
(Andy Postnikov)
5052

5153
09 Jul 2020, PHP 7.4.8
5254

ext/standard/dns.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,8 @@ static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
362362
Check DNS records corresponding to a given Internet host name or IP address */
363363
PHP_FUNCTION(dns_check_record)
364364
{
365-
#ifndef MAXPACKET
366-
#define MAXPACKET 8192 /* max packet size used internally by BIND */
367-
#endif
368-
u_char ans[MAXPACKET];
365+
HEADER *hp;
366+
querybuf answer;
369367
char *hostname, *rectype = NULL;
370368
size_t hostname_len, rectype_len = 0;
371369
int type = DNS_T_MX, i;
@@ -423,14 +421,14 @@ PHP_FUNCTION(dns_check_record)
423421
res_init();
424422
#endif
425423

426-
RETVAL_TRUE;
427-
i = php_dns_search(handle, hostname, C_IN, type, ans, sizeof(ans));
424+
i = php_dns_search(handle, hostname, C_IN, type, answer.qb2, sizeof answer);
425+
php_dns_free_handle(handle);
428426

429427
if (i < 0) {
430-
RETVAL_FALSE;
428+
RETURN_FALSE;
431429
}
432-
433-
php_dns_free_handle(handle);
430+
hp = (HEADER *)&answer;
431+
RETURN_BOOL(ntohs(hp->ancount) != 0);
434432
}
435433
/* }}} */
436434

@@ -1050,7 +1048,7 @@ PHP_FUNCTION(dns_get_mx)
10501048
zval *mx_list, *weight_list = NULL;
10511049
int count, qdc;
10521050
u_short type, weight;
1053-
u_char ans[MAXPACKET];
1051+
querybuf answer;
10541052
char buf[MAXHOSTNAMELEN];
10551053
HEADER *hp;
10561054
u_char *cp, *end;
@@ -1097,16 +1095,14 @@ PHP_FUNCTION(dns_get_mx)
10971095
res_init();
10981096
#endif
10991097

1100-
i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, (u_char *)&ans, sizeof(ans));
1098+
i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, answer.qb2, sizeof answer);
11011099
if (i < 0) {
1100+
php_dns_free_handle(handle);
11021101
RETURN_FALSE;
11031102
}
1104-
if (i > (int)sizeof(ans)) {
1105-
i = sizeof(ans);
1106-
}
1107-
hp = (HEADER *)&ans;
1108-
cp = (u_char *)&ans + HFIXEDSZ;
1109-
end = (u_char *)&ans +i;
1103+
hp = (HEADER *)&answer;
1104+
cp = answer.qb2 + HFIXEDSZ;
1105+
end = answer.qb2 + i;
11101106
for (qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) {
11111107
if ((i = dn_skipname(cp, end)) < 0 ) {
11121108
php_dns_free_handle(handle);
@@ -1128,7 +1124,7 @@ PHP_FUNCTION(dns_get_mx)
11281124
continue;
11291125
}
11301126
GETSHORT(weight, cp);
1131-
if ((i = dn_expand(ans, end, cp, buf, sizeof(buf)-1)) < 0) {
1127+
if ((i = dn_expand(answer.qb2, end, cp, buf, sizeof(buf)-1)) < 0) {
11321128
php_dns_free_handle(handle);
11331129
RETURN_FALSE;
11341130
}

0 commit comments

Comments
 (0)