From c28407a1c9b0a45de91f34cf3f27ae5c0da591a3 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Fri, 2 Sep 2022 10:28:19 +0200 Subject: [PATCH] FIX : default value for bom_id with $this->id and protection against infinite loop --- htdocs/bom/bom_card.php | 2 +- htdocs/bom/class/bom.class.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 669eb70d069..573478a6b3d 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -182,7 +182,7 @@ if (empty($reshook)) { // We check if we're allowed to add this bom $TParentBom=array(); - $object->getParentBomTreeRecursive($TParentBom, $object->id); + $object->getParentBomTreeRecursive($TParentBom); if ($bom_child_id > 0 && !empty($TParentBom) && in_array($bom_child_id, $TParentBom)) { $n_child = new BOM($db); $n_child->fetch($bom_child_id); diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 6cd1d1d42d8..374d4af248b 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -1153,11 +1153,19 @@ class BOM extends CommonObject * * @param array $TParentBom We put all found parent bom in $TParentBom * @param int $bom_id ID of bom from which we want to get parent bom ids + * @param int $level Protection against infinite loop * @return void */ - public function getParentBomTreeRecursive(&$TParentBom, $bom_id) + public function getParentBomTreeRecursive(&$TParentBom, $bom_id='', $level=1) { + // Protection against infinite loop + if ($level > 1000) { + return 0; + } + + if(empty($bom_id)) $bom_id=$this->id; + $sql = 'SELECT l.fk_bom, b.label FROM '.MAIN_DB_PREFIX.'bom_bomline l INNER JOIN '.MAIN_DB_PREFIX.$this->table_element.' b ON b.rowid = l.fk_bom @@ -1167,7 +1175,7 @@ class BOM extends CommonObject if (!empty($resql)) { while ($res = $this->db->fetch_object($resql)) { $TParentBom[$res->fk_bom] = $res->fk_bom; - $this->getParentBomTreeRecursive($TParentBom, $res->fk_bom); + $this->getParentBomTreeRecursive($TParentBom, $res->fk_bom, $level+1); } } }