Skip to content

Commit 1c0ee68

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix bug #78008: dns_check_record() always return true on Alpine
2 parents 5785a15 + 2053329 commit 1c0ee68

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

ext/standard/dns.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,8 @@ static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
353353
/* {{{ Check DNS records corresponding to a given Internet host name or IP address */
354354
PHP_FUNCTION(dns_check_record)
355355
{
356-
#ifndef MAXPACKET
357-
#define MAXPACKET 8192 /* max packet size used internally by BIND */
358-
#endif
359-
u_char ans[MAXPACKET];
356+
HEADER *hp;
357+
querybuf answer;
360358
char *hostname, *rectype = NULL;
361359
size_t hostname_len, rectype_len = 0;
362360
int type = DNS_T_MX, i;
@@ -414,14 +412,14 @@ PHP_FUNCTION(dns_check_record)
414412
res_init();
415413
#endif
416414

417-
RETVAL_TRUE;
418-
i = php_dns_search(handle, hostname, C_IN, type, ans, sizeof(ans));
415+
i = php_dns_search(handle, hostname, C_IN, type, answer.qb2, sizeof answer);
416+
php_dns_free_handle(handle);
419417

420418
if (i < 0) {
421-
RETVAL_FALSE;
419+
RETURN_FALSE;
422420
}
423-
424-
php_dns_free_handle(handle);
421+
hp = (HEADER *)&answer;
422+
RETURN_BOOL(ntohs(hp->ancount) != 0);
425423
}
426424
/* }}} */
427425

@@ -1039,7 +1037,7 @@ PHP_FUNCTION(dns_get_mx)
10391037
zval *mx_list, *weight_list = NULL;
10401038
int count, qdc;
10411039
u_short type, weight;
1042-
u_char ans[MAXPACKET];
1040+
querybuf answer;
10431041
char buf[MAXHOSTNAMELEN];
10441042
HEADER *hp;
10451043
u_char *cp, *end;
@@ -1086,16 +1084,14 @@ PHP_FUNCTION(dns_get_mx)
10861084
res_init();
10871085
#endif
10881086

1089-
i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, (u_char *)&ans, sizeof(ans));
1087+
i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, answer.qb2, sizeof answer);
10901088
if (i < 0) {
1089+
php_dns_free_handle(handle);
10911090
RETURN_FALSE;
10921091
}
1093-
if (i > (int)sizeof(ans)) {
1094-
i = sizeof(ans);
1095-
}
1096-
hp = (HEADER *)&ans;
1097-
cp = (u_char *)&ans + HFIXEDSZ;
1098-
end = (u_char *)&ans +i;
1092+
hp = (HEADER *)&answer;
1093+
cp = answer.qb2 + HFIXEDSZ;
1094+
end = answer.qb2 + i;
10991095
for (qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) {
11001096
if ((i = dn_skipname(cp, end)) < 0 ) {
11011097
php_dns_free_handle(handle);
@@ -1117,7 +1113,7 @@ PHP_FUNCTION(dns_get_mx)
11171113
continue;
11181114
}
11191115
GETSHORT(weight, cp);
1120-
if ((i = dn_expand(ans, end, cp, buf, sizeof(buf)-1)) < 0) {
1116+
if ((i = dn_expand(answer.qb2, end, cp, buf, sizeof(buf)-1)) < 0) {
11211117
php_dns_free_handle(handle);
11221118
RETURN_FALSE;
11231119
}

0 commit comments

Comments
 (0)