Add error handling for config xml parsing exceptions. Fix #15860

With this change, exceptions during a config restore will no longer
result in an unbootable instance.
This commit is contained in:
Marcos Mendoza 2024-12-04 12:16:35 -06:00
parent e4b8c5b600
commit e930812c68

View File

@ -201,11 +201,16 @@ function parse_xml_config_raw($cffile, $rootobj, $isstring = "false") {
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
log_error(sprintf(gettext('XML error: %1$s at line %2$d in %3$s') . "\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser),
$cffile));
try {
if (!xml_parse($xml_parser, $data, feof($fp))) {
log_error(sprintf(gettext('XML error: %1$s at line %2$d in %3$s') . "\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser),
$cffile));
return -1;
}
} catch (\Throwable | \Error | \Exception $e) {
log_error($e->getMessage());
return -1;
}
}