From 58ab03e0cf1ff9223720b9f480d29706560d0232 Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Mon, 3 Jan 2022 17:17:20 +0530 Subject: [PATCH] No validation for field id_parent. If a non existing category id sent, fatal error occurrs. --- classes/Category.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/classes/Category.php b/classes/Category.php index 9ba9d8d1a..e64fb6b2d 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -122,7 +122,7 @@ class CategoryCore extends ObjectModel 'objectsNodeName' => 'categories', 'hidden_fields' => array('nleft', 'nright', 'groupBox'), 'fields' => array( - 'id_parent' => array('xlink_resource'=> 'categories'), + 'id_parent' => array('xlink_resource'=> 'categories', 'setter' => 'setWsParentCategory'), 'level_depth' => array('setter' => false), 'nb_products_recursive' => array('getter' => 'getWsNbProductsRecursive', 'setter' => false), ), @@ -1886,4 +1886,16 @@ class CategoryCore extends ObjectModel WHERE `id_category` = '.(int)$this->id.' AND `id_shop` = '.(int)$id_shop); } + + public function setWsParentCategory($id_parent_category) + { + if (!$id_parent_category || !Validate::isLoadedObject(new Category((int)$id_parent_category))) { + WebserviceRequest::getInstance()->setError(400, 'Wrong parent category id passed.', 134); + return false; + } + + $this->id_parent = $id_parent_category; + + return true; + } }