storage/State: check if a CompositeStorage exists; fixes nullptr dereference

Fixes another crash bug caused by commit
64d141f71e
This commit is contained in:
Max Kellermann 2018-01-02 14:13:26 +01:00
parent 08db28469d
commit ff624075a8
2 changed files with 15 additions and 0 deletions

3
NEWS
View File

@ -1,4 +1,7 @@
ver 0.20.15 (not yet released)
* state file
- make mount point restore errors non-fatal
- fix crash when restoring mounts with incompatible database plugin
ver 0.20.14 (2018/01/01)
* database

View File

@ -48,6 +48,9 @@ static constexpr Domain storage_domain("storage");
void
storage_state_save(BufferedOutputStream &os, const Instance &instance)
{
if (instance.storage == nullptr)
return;
const auto visitor = [&os](const char *mount_uri, const Storage &storage) {
std::string uri = storage.MapUTF8("");
if (uri.empty() || StringIsEmpty(mount_uri))
@ -85,6 +88,12 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
FormatError(storage_domain, "Unrecognized line in mountpoint state: %s", line);
}
if (instance.storage == nullptr)
/* without storage (a CompositeStorage instance), we
cannot mount, and therefore we silently ignore the
state file */
return true;
if (url.empty() || uri.empty()) {
LogError(storage_domain, "Missing value in mountpoint state.");
return true;
@ -120,6 +129,9 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
unsigned
storage_state_get_hash(const Instance &instance)
{
if (instance.storage == nullptr)
return 0;
std::set<std::string> mounts;
const auto visitor = [&mounts](const char *mount_uri, const Storage &storage) {