From e95e2905324da765bd4c9a2e852600dd885d197e Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 29 Mar 2023 08:35:30 +0800 Subject: [PATCH] MDL-77783 core: Validate sublugins.json * Validate the decoded subplugins.json before processing it. * Log errors if subplugins.json is invalid or if plugintypes is not defined. --- lib/classes/component.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/classes/component.php b/lib/classes/component.php index eed558d6d80..eb535292c5a 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -574,7 +574,18 @@ $cache = '.var_export($cache, true).'; $types = array(); $subplugins = array(); if (file_exists("$ownerdir/db/subplugins.json")) { - $subplugins = (array) json_decode(file_get_contents("$ownerdir/db/subplugins.json"))->plugintypes; + $subplugins = []; + $subpluginsjson = json_decode(file_get_contents("$ownerdir/db/subplugins.json")); + if (json_last_error() === JSON_ERROR_NONE) { + if (!empty($subpluginsjson->plugintypes)) { + $subplugins = (array) $subpluginsjson->plugintypes; + } else { + error_log("No plugintypes defined in $ownerdir/db/subplugins.json"); + } + } else { + $jsonerror = json_last_error_msg(); + error_log("$ownerdir/db/subplugins.json is invalid ($jsonerror)"); + } } else if (file_exists("$ownerdir/db/subplugins.php")) { error_log('Use of subplugins.php has been deprecated. ' . "Please update your '$ownerdir' plugin to provide a subplugins.json file instead.");