From 58c7519598b39f58ec2ff1a821ace113f523b0fa Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Thu, 12 Mar 2015 19:34:05 -0400 Subject: [PATCH] Add a magic number to settings.dat for better identification. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “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 --- client/settings.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/settings.cc b/client/settings.cc index b4e5f434..aa2c4f8f 100644 --- a/client/settings.cc +++ b/client/settings.cc @@ -28,19 +28,24 @@ namespace crashpad { 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 { kUploadsEnabled = 1 << 0, }; - Data() : version(kSettingsVersion), + Data() : magic(kSettingsMagic), + version(kSettingsVersion), options(0), + padding_0(0), last_upload_attempt_time(0), client_id() {} + uint32_t magic; uint32_t version; uint32_t options; + uint32_t padding_0; uint64_t last_upload_attempt_time; // time_t UUID client_id; }; @@ -193,6 +198,11 @@ bool Settings::ReadSettings(FileHandle handle, Data* out_data) { if (!LoggingReadFile(handle, out_data, sizeof(*out_data))) return false; + if (out_data->magic != Data::kSettingsMagic) { + LOG(ERROR) << "Settings magic is not " << Data::kSettingsMagic; + return false; + } + if (out_data->version != Data::kSettingsVersion) { LOG(ERROR) << "Settings version is not " << Data::kSettingsVersion; return false;