Skip to content

Commit 0bf259b

Browse files
committed
dns_check_record() always return true on Alpinelinux #78088
- free handle before return result - cleaned up remaining usage of MAXPACKET - update dns_get_mx() to use the same approach
1 parent 7c16d11 commit 0bf259b

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

ext/standard/dns.c

Lines changed: 14 additions & 17 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;
@@ -415,13 +413,14 @@ PHP_FUNCTION(dns_check_record)
415413
#endif
416414

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

420419
if (i < 0) {
421-
RETVAL_FALSE;
420+
RETURN_FALSE;
422421
}
423-
424-
php_dns_free_handle(handle);
422+
hp = (HEADER *)&answer;
423+
RETURN_BOOL(ntohs(hp->ancount) != 0);
425424
}
426425
/* }}} */
427426

@@ -1039,7 +1038,7 @@ PHP_FUNCTION(dns_get_mx)
10391038
zval *mx_list, *weight_list = NULL;
10401039
int count, qdc;
10411040
u_short type, weight;
1042-
u_char ans[MAXPACKET];
1041+
querybuf answer;
10431042
char buf[MAXHOSTNAMELEN];
10441043
HEADER *hp;
10451044
u_char *cp, *end;
@@ -1086,16 +1085,14 @@ PHP_FUNCTION(dns_get_mx)
10861085
res_init();
10871086
#endif
10881087

1089-
i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, (u_char *)&ans, sizeof(ans));
1088+
i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, answer.qb2, sizeof answer);
10901089
if (i < 0) {
1090+
php_dns_free_handle(handle);
10911091
RETURN_FALSE;
10921092
}
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;
1093+
hp = (HEADER *)&answer;
1094+
cp = answer.qb2 + HFIXEDSZ;
1095+
end = answer.qb2 + i;
10991096
for (qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) {
11001097
if ((i = dn_skipname(cp, end)) < 0 ) {
11011098
php_dns_free_handle(handle);
@@ -1117,7 +1114,7 @@ PHP_FUNCTION(dns_get_mx)
11171114
continue;
11181115
}
11191116
GETSHORT(weight, cp);
1120-
if ((i = dn_expand(ans, end, cp, buf, sizeof(buf)-1)) < 0) {
1117+
if ((i = dn_expand(answer.qb2, end, cp, buf, sizeof(buf)-1)) < 0) {
11211118
php_dns_free_handle(handle);
11221119
RETURN_FALSE;
11231120
}

0 commit comments

Comments
 (0)