From 996cfa3dae5ae73bf8ecad33f1377712b0203d17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org>
Date: Thu, 26 Aug 2021 15:34:29 +0200
Subject: [PATCH] :ambulance: fix(core) Avoid PHP errors when an object type as
 an invalid ou

issue #6188
---
 include/class_objects.inc | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/include/class_objects.inc b/include/class_objects.inc
index 44f6798bc..33732f50c 100644
--- a/include/class_objects.inc
+++ b/include/class_objects.inc
@@ -440,16 +440,18 @@ class objects
         $infos['filterRDN'] = '';
       } else {
         $parts = ldap_explode_dn(preg_replace('/,$/', '', $infos['ou']), 0);
-        unset($parts['count']);
-        $dnFilter = [];
-        foreach ($parts as $part) {
-          preg_match('/([^=]+)=(.*)$/', $part, $m);
-          $dnFilter[] = '('.$m[1].':dn:='.$m[2].')';
-        }
-        if (count($dnFilter) > 1) {
-          $infos['filterRDN'] = '(&'.implode('', $dnFilter).')';
-        } else {
-          $infos['filterRDN'] = $dnFilter[0];
+        if ($parts !== FALSE) {
+          unset($parts['count']);
+          $dnFilter = [];
+          foreach ($parts as $part) {
+            preg_match('/([^=]+)=(.*)$/', $part, $m);
+            $dnFilter[] = '('.$m[1].':dn:='.$m[2].')';
+          }
+          if (count($dnFilter) > 1) {
+            $infos['filterRDN'] = '(&'.implode('', $dnFilter).')';
+          } else {
+            $infos['filterRDN'] = $dnFilter[0];
+          }
         }
       }
     }
-- 
GitLab