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.
This commit is contained in:
Jun Pataleta 2023-03-29 08:35:30 +08:00
parent 449a8b0b31
commit c99abd65ca

View File

@ -554,7 +554,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.");