Skip to content

Commit

Permalink
Fix config_del_path() if the node doesn't exist
Browse files Browse the repository at this point in the history
If the node we're trying to delete with config_del_path() doesn't exist
array_del_path() will fail as follows:

Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /etc/inc/util.inc:3459
Stack trace:
  thrown in /etc/inc/util.inc on line 3459
PHP ERROR: Type: 1, File: /etc/inc/util.inc, Line: 3459, Message: Uncaught TypeError: Cannot access offset of type string on string in /etc/inc/util.inc:3459
Stack trace:
  thrown

Check to make sure the element we found is an array and contains the key
we're trying to delete before we try to delete it.
  • Loading branch information
kprovost committed Nov 14, 2022
1 parent 3f5702a commit 9a9a6b3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/etc/inc/util.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3452,6 +3452,11 @@ function array_del_path(array &$arr, string $path) {
return null;
}
}

if (!(is_array($el) && array_key_exists($vkey, $el))) {
return null;
}

$ret = $el[$vkey];
unset($el[$vkey]);
return ($ret);
Expand Down

0 comments on commit 9a9a6b3

Please sign in to comment.