Add a magic number to settings.dat for better identification.

“1” is probably one of the more common things for files to begin with.

R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1007433003
This commit is contained in:
Mark Mentovai 2015-03-12 19:34:05 -04:00
parent 94471409a1
commit 58c7519598

View File

@ -28,19 +28,24 @@
namespace crashpad { namespace crashpad {
struct ALIGNAS(4) Settings::Data { struct ALIGNAS(4) Settings::Data {
static const uint16_t kSettingsVersion = 1; static const uint32_t kSettingsMagic = 'CPds';
static const uint32_t kSettingsVersion = 1;
enum Options : uint32_t { enum Options : uint32_t {
kUploadsEnabled = 1 << 0, kUploadsEnabled = 1 << 0,
}; };
Data() : version(kSettingsVersion), Data() : magic(kSettingsMagic),
version(kSettingsVersion),
options(0), options(0),
padding_0(0),
last_upload_attempt_time(0), last_upload_attempt_time(0),
client_id() {} client_id() {}
uint32_t magic;
uint32_t version; uint32_t version;
uint32_t options; uint32_t options;
uint32_t padding_0;
uint64_t last_upload_attempt_time; // time_t uint64_t last_upload_attempt_time; // time_t
UUID client_id; UUID client_id;
}; };
@ -193,6 +198,11 @@ bool Settings::ReadSettings(FileHandle handle, Data* out_data) {
if (!LoggingReadFile(handle, out_data, sizeof(*out_data))) if (!LoggingReadFile(handle, out_data, sizeof(*out_data)))
return false; return false;
if (out_data->magic != Data::kSettingsMagic) {
LOG(ERROR) << "Settings magic is not " << Data::kSettingsMagic;
return false;
}
if (out_data->version != Data::kSettingsVersion) { if (out_data->version != Data::kSettingsVersion) {
LOG(ERROR) << "Settings version is not " << Data::kSettingsVersion; LOG(ERROR) << "Settings version is not " << Data::kSettingsVersion;
return false; return false;