From 6db40c27e31b3c1d1166672ac4ce3c9ed667fe7b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org>
Date: Thu, 28 Jan 2021 14:21:14 +0100
Subject: [PATCH] :ambulance: fix(errors) Avoid errors when using a partial
 object in error handling

Object might not be finished when the error happens, take extra precautions

issue #6144
---
 include/errors/class_SimplePluginError.inc     | 12 ++++++------
 include/errors/class_SimplePluginHookError.inc |  6 +++---
 include/errors/class_SimplePluginLdapError.inc |  6 +++---
 include/simpleplugin/class_simpleTabs.inc      |  9 ++++-----
 4 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/include/errors/class_SimplePluginError.inc b/include/errors/class_SimplePluginError.inc
index 38825899f..0bb239ac5 100644
--- a/include/errors/class_SimplePluginError.inc
+++ b/include/errors/class_SimplePluginError.inc
@@ -61,8 +61,8 @@ class SimplePluginError extends FusionDirectoryError
   {
     $array = parent::toArray();
 
-    if (isset($this->object)) {
-      $array['dn']  = $this->object->getBaseObject()->dn;
+    if (isset($this->object->dn)) {
+      $array['dn']  = $this->object->dn;
     }
 
     if (isset($this->tab)) {
@@ -80,8 +80,8 @@ class SimplePluginError extends FusionDirectoryError
   {
     $msg = '';
 
-    if (isset($this->object)) {
-      $msg .= $this->object->getBaseObject()->dn.' > ';
+    if (isset($this->object->dn)) {
+      $msg .= $this->object->dn.' > ';
     }
 
     if (isset($this->tab) && isset($this->tab->parent->by_name[get_class($this->tab)])) {
@@ -106,8 +106,8 @@ class SimplePluginError extends FusionDirectoryError
 
     $breadcrumbs = [];
 
-    if (isset($this->object)) {
-      $breadcrumbs[] = htmlescape($this->object->getBaseObject()->dn);
+    if (isset($this->object->dn)) {
+      $breadcrumbs[] = htmlescape($this->object->dn);
     }
 
     if (isset($this->tab) && isset($this->tab->parent->by_name[get_class($this->tab)])) {
diff --git a/include/errors/class_SimplePluginHookError.inc b/include/errors/class_SimplePluginHookError.inc
index 86f35c889..c7a693a27 100644
--- a/include/errors/class_SimplePluginHookError.inc
+++ b/include/errors/class_SimplePluginHookError.inc
@@ -46,11 +46,11 @@ class SimplePluginHookError extends SimplePluginError
   {
     $html = '';
 
-    if (isset($this->object)) {
-      $html .= htmlescape($this->object->getBaseObject()->dn.' > ');
+    if (isset($this->object->dn)) {
+      $html .= htmlescape($this->object->dn.' > ');
     }
 
-    if (isset($this->tab)) {
+    if (isset($this->tab) && isset($this->tab->parent->by_name[get_class($this->tab)])) {
       $html .= htmlescape($this->tab->parent->by_name[get_class($this->tab)].' > ');
     }
 
diff --git a/include/errors/class_SimplePluginLdapError.inc b/include/errors/class_SimplePluginLdapError.inc
index b2830937a..5f05144f6 100644
--- a/include/errors/class_SimplePluginLdapError.inc
+++ b/include/errors/class_SimplePluginLdapError.inc
@@ -53,11 +53,11 @@ class SimplePluginLdapError extends SimplePluginError
   {
     $html = '';
 
-    if (isset($this->object)) {
-      $html .= htmlescape($this->object->getBaseObject()->dn.' > ');
+    if (isset($this->object->dn)) {
+      $html .= htmlescape($this->object->dn.' > ');
     }
 
-    if (isset($this->tab)) {
+    if (isset($this->tab) && isset($this->tab->parent->by_name[get_class($this->tab)])) {
       $html .= htmlescape($this->tab->parent->by_name[get_class($this->tab)].' > ');
     }
 
diff --git a/include/simpleplugin/class_simpleTabs.inc b/include/simpleplugin/class_simpleTabs.inc
index ac2555b16..55f909f0c 100644
--- a/include/simpleplugin/class_simpleTabs.inc
+++ b/include/simpleplugin/class_simpleTabs.inc
@@ -73,7 +73,7 @@ class simpleTabs implements FusionDirectoryDialog
       );
     }
 
-    $baseobject         = NULL;
+    $this->baseclass = NULL;
     foreach ($data as $tab) {
       if (!plugin_available($tab['CLASS'])) {
         continue;
@@ -85,12 +85,11 @@ class simpleTabs implements FusionDirectoryDialog
       $this->by_name[$tab['CLASS']]   = $tab['NAME'];
       $this->plNotify[$tab['CLASS']]  = FALSE;
 
-      if ($baseobject === NULL) {
-        $baseobject = new $tab['CLASS']($this->dn, $attrs_object, $this, TRUE);
-        $this->by_object[$tab['CLASS']] = $baseobject;
+      if ($this->baseclass === NULL) {
+        $this->by_object[$tab['CLASS']] = new $tab['CLASS']($this->dn, $attrs_object, $this, TRUE);
         $this->baseclass                = $tab['CLASS'];
       } else {
-        $this->by_object[$tab['CLASS']] = new $tab['CLASS']($this->dn, $baseobject, $this, FALSE);
+        $this->by_object[$tab['CLASS']] = new $tab['CLASS']($this->dn, $this->by_object[$this->baseclass], $this, FALSE);
       }
 
       $this->by_object[$tab['CLASS']]->set_acl_category($this->acl_category);
-- 
GitLab