Skip to content

Commit 2c57378

Browse files
andypostnikic
authored andcommitted
Fix bug #78008: dns_check_record() always return true on Alpine
- free handle before return result - cleaned up remaining usage of MAXPACKET - update dns_get_mx() to use the same approach Closes phpGH-5854.
1 parent ce149b0 commit 2c57378

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
@@ -31,6 +31,8 @@ PHP NEWS
3131
- Standard:
3232
. Fixed bug #70362 (Can't copy() large 'data://' with open_basedir). (cmb)
3333
. Fixed bug #79817 (str_replace() does not handle INDIRECT elements). (Nikita)
34+
. Fixed bug #78008 (dns_check_record() always return true on Alpine).
35+
(Andy Postnikov)
3436

3537
?? ??? ????, PHP 7.3.20
3638

ext/standard/dns.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,8 @@ static void _php_dns_free_res(struct __res_state *res) { /* {{{ */
349349
Check DNS records corresponding to a given Internet host name or IP address */
350350
PHP_FUNCTION(dns_check_record)
351351
{
352-
#ifndef MAXPACKET
353-
#define MAXPACKET 8192 /* max packet size used internally by BIND */
354-
#endif
355-
u_char ans[MAXPACKET];
352+
HEADER *hp;
353+
querybuf answer;
356354
char *hostname, *rectype = NULL;
357355
size_t hostname_len, rectype_len = 0;
358356
int type = T_MX, i;
@@ -410,14 +408,14 @@ PHP_FUNCTION(dns_check_record)
410408
res_init();
411409
#endif
412410

413-
RETVAL_TRUE;
414-
i = php_dns_search(handle, hostname, C_IN, type, ans, sizeof(ans));
411+
i = php_dns_search(handle, hostname, C_IN, type, answer.qb2, sizeof answer);
412+
php_dns_free_handle(handle);
415413

416414
if (i < 0) {
417-
RETVAL_FALSE;
415+
RETURN_FALSE;
418416
}
419-
420-
php_dns_free_handle(handle);
417+
hp = (HEADER *)&answer;
418+
RETURN_BOOL(ntohs(hp->ancount) != 0);
421419
}
422420
/* }}} */
423421

@@ -1033,7 +1031,7 @@ PHP_FUNCTION(dns_get_mx)
10331031
zval *mx_list, *weight_list = NULL;
10341032
int count, qdc;
10351033
u_short type, weight;
1036-
u_char ans[MAXPACKET];
1034+
querybuf answer;
10371035
char buf[MAXHOSTNAMELEN];
10381036
HEADER *hp;
10391037
u_char *cp, *end;
@@ -1076,16 +1074,14 @@ PHP_FUNCTION(dns_get_mx)
10761074
res_init();
10771075
#endif
10781076

1079-
i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, (u_char *)&ans, sizeof(ans));
1077+
i = php_dns_search(handle, hostname, C_IN, DNS_T_MX, answer.qb2, sizeof answer);
10801078
if (i < 0) {
1079+
php_dns_free_handle(handle);
10811080
RETURN_FALSE;
10821081
}
1083-
if (i > (int)sizeof(ans)) {
1084-
i = sizeof(ans);
1085-
}
1086-
hp = (HEADER *)&ans;
1087-
cp = (u_char *)&ans + HFIXEDSZ;
1088-
end = (u_char *)&ans +i;
1082+
hp = (HEADER *)&answer;
1083+
cp = answer.qb2 + HFIXEDSZ;
1084+
end = answer.qb2 + i;
10891085
for (qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) {
10901086
if ((i = dn_skipname(cp, end)) < 0 ) {
10911087
php_dns_free_handle(handle);
@@ -1107,7 +1103,7 @@ PHP_FUNCTION(dns_get_mx)
11071103
continue;
11081104
}
11091105
GETSHORT(weight, cp);
1110-
if ((i = dn_expand(ans, end, cp, buf, sizeof(buf)-1)) < 0) {
1106+
if ((i = dn_expand(answer.qb2, end, cp, buf, sizeof(buf)-1)) < 0) {
11111107
php_dns_free_handle(handle);
11121108
RETURN_FALSE;
11131109
}

0 commit comments

Comments
 (0)