Skip to content

Commit a4c55ee

Browse files
committed
Merge remote-tracking branch 'security/bug76248' into PHP-5.6
* security/bug76248: Fix bug #76248 - Malicious LDAP-Server Response causes Crash
2 parents 6e64aba + 49782c5 commit a4c55ee

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

ext/ldap/ldap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,11 @@ PHP_FUNCTION(ldap_get_entries)
11031103

11041104
add_assoc_long(tmp1, "count", num_attrib);
11051105
dn = ldap_get_dn(ldap, ldap_result_entry);
1106-
add_assoc_string(tmp1, "dn", dn, 1);
1106+
if (dn) {
1107+
add_assoc_string(tmp1, "dn", dn, 1);
1108+
} else {
1109+
add_assoc_null(tmp1, "dn");
1110+
}
11071111
#if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS
11081112
ldap_memfree(dn);
11091113
#else

ext/ldap/tests/bug76248.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #76248 (Malicious LDAP-Server Response causes Crash)
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
if (!function_exists('pcntl_fork')) die('skip fork not available');
7+
?>
8+
--FILE--
9+
<?php
10+
$pid = pcntl_fork();
11+
const PORT = 12345;
12+
if ($pid == 0) {
13+
// child
14+
$server = stream_socket_server("tcp://127.0.0.1:12345");
15+
$socket = stream_socket_accept($server, 3);
16+
fwrite($socket, base64_decode("MAwCAQFhBwoBAAQABAAweQIBAmR0BJljbj1yb290LGRjPWV4YW1wbGUsZGM9Y29tMFcwIwQLb2JqZWN0Q2xhc3MxFAQSb3JnYW5pemF0aW9uYWxSb2xlMAwEAmNuMQYEBHJvb3QwIgQLZGVzY3JpcHRpb24xEwQRRGlyZWN0b3J5IE1hbmFnZXIwDAIBAmUHCgEABAAEADB5AgEDZHQEmWNuPXJvb3QsZGM9ZXhhbXBsZSxkYz1jb20wVzAjBAtvYmplY3RDbGFzczEUBBJvcmdhbml6YXRpb25hbFJvbGUwDAQCY24xBgQEcm9vdDAiBAtkZXNjcmlwdGlvbjETBBFEaXJlY3RvcnkgTWFuYWdlcjAMAgEDZQcKAQAEAAQA"));
17+
fflush($socket);
18+
} else {
19+
// parent
20+
$ds = ldap_connect("127.0.0.1", PORT);
21+
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
22+
$b = ldap_bind($ds, "cn=root,dc=example,dc=com", "secret");
23+
24+
$s = ldap_search($ds, "dc=example,dc=com", "(cn=root)");
25+
$tt = ldap_get_entries($ds, $s);
26+
var_dump($tt);
27+
}
28+
?>
29+
--EXPECT--
30+
array(2) {
31+
["count"]=>
32+
int(1)
33+
[0]=>
34+
array(2) {
35+
["count"]=>
36+
int(0)
37+
["dn"]=>
38+
NULL
39+
}
40+
}

0 commit comments

Comments
 (0)