MDL-55617 backup: Possible fatal errors in backup and restore
The unserialize() function will not always return an object especially when as can happen the controller field of a record in the backup_controllers table is empty. This change ensures that in this case the script will not cause a fatal error, but instead throw an error.
This commit is contained in:
@@ -105,6 +105,12 @@ abstract class backup_controller_dbops extends backup_dbops {
|
||||
throw new backup_dbops_exception('backup_controller_dbops_nonexisting');
|
||||
}
|
||||
$controller = unserialize(base64_decode($controllerrec->controller));
|
||||
if (!is_object($controller)) {
|
||||
// The controller field of the table did not contain a serialized object.
|
||||
// It is made empty after it has been used successfully, it is likely that
|
||||
// the user has pressed the browser back button at some point.
|
||||
throw new backup_dbops_exception('backup_controller_dbops_loading_invalid_controller');
|
||||
}
|
||||
// Check checksum is ok. Sounds silly but it isn't ;-)
|
||||
if (!$controller->is_checksum_correct($controllerrec->checksum)) {
|
||||
throw new backup_dbops_exception('backup_controller_dbops_loading_checksum_mismatch');
|
||||
|
||||
@@ -95,6 +95,12 @@ abstract class restore_controller_dbops extends restore_dbops {
|
||||
throw new backup_dbops_exception('restore_controller_dbops_nonexisting');
|
||||
}
|
||||
$controller = unserialize(base64_decode($controllerrec->controller));
|
||||
if (!is_object($controller)) {
|
||||
// The controller field of the table did not contain a serialized object.
|
||||
// It is made empty after it has been used successfully, it is likely that
|
||||
// the user has pressed the browser back button at some point.
|
||||
throw new backup_dbops_exception('restore_controller_dbops_loading_invalid_controller');
|
||||
}
|
||||
// Check checksum is ok. Sounds silly but it isn't ;-)
|
||||
if (!$controller->is_checksum_correct($controllerrec->checksum)) {
|
||||
throw new backup_dbops_exception('restore_controller_dbops_loading_checksum_mismatch');
|
||||
|
||||
Reference in New Issue
Block a user