Validate the value of a UserStatusDirective read from disk.

Summary: Follow-up work from D4181868.

Reviewed By: simpkins

Differential Revision: D4256227

fbshipit-source-id: 3e40a0cae4ab132046d96029d2881c2127ed4c83
This commit is contained in:
Michael Bolin 2016-11-30 19:03:17 -08:00 committed by Facebook Github Bot
parent 0e613bd96b
commit 1cd336846e

View File

@ -49,7 +49,13 @@ DirstatePersistence::load() {
auto dirstateData =
CompactSerializer::deserialize<overlay::DirstateData>(serializedData);
for (auto& pair : dirstateData.directives) {
entries[RelativePath(pair.first)] = pair.second;
auto name = overlay::_UserStatusDirective_VALUES_TO_NAMES.find(pair.second);
if (name != overlay::_UserStatusDirective_VALUES_TO_NAMES.end()) {
entries[RelativePath(pair.first)] = pair.second;
} else {
throw std::runtime_error(folly::to<std::string>(
"Illegal enum value for UserStatusDirective: ", pair.second));
}
}
return entries;