Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ PHP_FUNCTION(dns_get_mx)
querybuf answer = {0};
char buf[MAXHOSTNAMELEN] = {0};
HEADER *hp;
uint8_t *cp, *end;
uint8_t *cp, *end, *rdend;
int i;
#if defined(HAVE_DNS_SEARCH)
struct sockaddr_storage from;
Expand Down Expand Up @@ -1126,19 +1126,28 @@ PHP_FUNCTION(dns_get_mx)
RETURN_FALSE;
}
cp += i;
if (cp + 10 > end) {
php_dns_free_handle(handle);
RETURN_FALSE;
}
GETSHORT(type, cp);
cp += INT16SZ + INT32SZ;
GETSHORT(i, cp);
if (type != DNS_T_MX) {
cp += i;
continue;
}
rdend = cp + i;
if (i < 2 || rdend > end) {
php_dns_free_handle(handle);
RETURN_FALSE;
}
GETSHORT(weight, cp);
if ((i = dn_expand(answer.qb2, end, cp, buf, sizeof(buf)-1)) < 0) {
if ((i = dn_expand(answer.qb2, rdend, cp, buf, sizeof(buf)-1)) < 0) {
php_dns_free_handle(handle);
RETURN_FALSE;
}
cp += i;
cp = rdend;
add_next_index_string(mx_list, buf);
if (weight_list) {
add_next_index_long(weight_list, weight);
Expand Down
21 changes: 21 additions & 0 deletions ext/standard/tests/dns/getmxrr_multiple.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
getmxrr() with multiple MX records
--SKIPIF--
<?php require "skipif.inc"; ?>
--FILE--
<?php
var_dump(getmxrr('multimx.basic.dnstest.php.net', $hosts, $weights));
$records = array_combine($hosts, $weights);
asort($records);
var_dump($records);
?>
--EXPECT--
bool(true)
array(3) {
["mx1.basic.dnstest.php.net"]=>
int(10)
["mail.example.com"]=>
int(20)
["multimx.basic.dnstest.php.net"]=>
int(30)
}
6 changes: 5 additions & 1 deletion ext/standard/tests/dns/zones/basic.dnstest.php.net.zone
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$TTL 86400
@ IN SOA ns1.basic.dnstest.php.net. hostmaster.basic.dnstest.php.net. (
2025100801 ; Serial
2025100802 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
Expand All @@ -13,4 +13,8 @@ ns1 IN A 127.0.0.1
www IN A 192.0.2.1
mx1 IN A 192.0.2.2

multimx IN MX 10 mx1.basic.dnstest.php.net.
multimx IN MX 20 mail.example.com.
multimx IN MX 30 multimx.basic.dnstest.php.net.

txt1 IN TXT "This is a test TXT record"
Loading