From 49782c54994ecca2ef2a061063bd5a7079c43527 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Sun, 22 Apr 2018 22:01:35 -0700 Subject: Fix bug #76248 - Malicious LDAP-Server Response causes Crash --- ext/ldap/ldap.c | 6 +++++- ext/ldap/tests/bug76248.phpt | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 ext/ldap/tests/bug76248.phpt diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 8ab0fe0727..03ca03d3ad 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -1103,7 +1103,11 @@ PHP_FUNCTION(ldap_get_entries) add_assoc_long(tmp1, "count", num_attrib); dn = ldap_get_dn(ldap, ldap_result_entry); - add_assoc_string(tmp1, "dn", dn, 1); + if (dn) { + add_assoc_string(tmp1, "dn", dn, 1); + } else { + add_assoc_null(tmp1, "dn"); + } #if (LDAP_API_VERSION > 2000) || HAVE_NSLDAP || HAVE_ORALDAP || WINDOWS ldap_memfree(dn); #else diff --git a/ext/ldap/tests/bug76248.phpt b/ext/ldap/tests/bug76248.phpt new file mode 100644 index 0000000000..45a7f83efb --- /dev/null +++ b/ext/ldap/tests/bug76248.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #76248 (Malicious LDAP-Server Response causes Crash) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +array(2) { + ["count"]=> + int(1) + [0]=> + array(2) { + ["count"]=> + int(0) + ["dn"]=> + NULL + } +} \ No newline at end of file -- cgit v1.2.1