diff options
author | James Hawkins <jhawkins@google.com> | 2016-07-28 20:45:42 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-07-28 20:45:42 +0000 |
commit | a99c4b0c86e581acf77c4d6eb129173f754ee42a (patch) | |
tree | 2b7f22625f1c0ea668b4a5f784e1656c31380b14 | |
parent | 26861dd5c2cdb207257dd88f6f0b88b71bb8f008 (diff) | |
parent | 01da3bb250c216a2e95282ab53b77a8e771bdb66 (diff) |
Merge \\\\"bootstat: Fix a potential unhandled exception for malformed input.\\\\" am: eafeb75c49 am: c45ec807ff am: c019082c26
am: 01da3bb250
Change-Id: Idf127e7d741690849d5e8ce528a7fa17d77b8775
-rw-r--r-- | bootstat/boot_event_record_store.cpp | 7 | ||||
-rw-r--r-- | bootstat/bootstat.cpp | 15 |
2 files changed, 17 insertions, 5 deletions
diff --git a/bootstat/boot_event_record_store.cpp b/bootstat/boot_event_record_store.cpp index ef4f68ec0..346eadae6 100644 --- a/bootstat/boot_event_record_store.cpp +++ b/bootstat/boot_event_record_store.cpp @@ -25,6 +25,7 @@ #include <utility> #include <android-base/file.h> #include <android-base/logging.h> +#include <android-base/parseint.h> #include "histogram_logger.h" #include "uptime_parser.h" @@ -57,8 +58,10 @@ bool ParseRecordEventTime(const std::string& path, int32_t* uptime) { // Ignore existing bootstat records (which do not contain file content). if (!content.empty()) { - int32_t value = std::stoi(content); - bootstat::LogHistogram("bootstat_mtime_matches_content", value == *uptime); + int32_t value; + if (android::base::ParseInt(content.c_str(), &value)) { + bootstat::LogHistogram("bootstat_mtime_matches_content", value == *uptime); + } } return true; diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index 7c1b7f38d..71a5a3993 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp @@ -28,6 +28,7 @@ #include <memory> #include <string> #include <android-base/logging.h> +#include <android-base/parseint.h> #include <cutils/properties.h> #include <log/log.h> #include "boot_event_record_store.h" @@ -56,8 +57,9 @@ void RecordBootEventFromCommandLine( BootEventRecordStore boot_event_store; if (!value_str.empty()) { int32_t value = 0; - value = std::stoi(value_str); - boot_event_store.AddBootEventWithValue(event, value); + if (android::base::ParseInt(value_str.c_str(), &value)) { + boot_event_store.AddBootEventWithValue(event, value); + } } else { boot_event_store.AddBootEvent(event); } @@ -187,7 +189,10 @@ std::string CalculateBootCompletePrefix() { std::string boot_complete_prefix = "boot_complete"; std::string build_date_str = GetProperty("ro.build.date.utc"); - int32_t build_date = std::stoi(build_date_str); + int32_t build_date; + if (!android::base::ParseInt(build_date_str.c_str(), &build_date)) { + return std::string(); + } BootEventRecordStore boot_event_store; BootEventRecordStore::BootEventRecord record; @@ -223,6 +228,10 @@ void RecordBootComplete() { // ota_boot_complete. The latter signifies that the device is booting after // a system update. std::string boot_complete_prefix = CalculateBootCompletePrefix(); + if (boot_complete_prefix.empty()) { + // The system is hosed because the build date property could not be read. + return; + } // post_decrypt_time_elapsed is only logged on encrypted devices. if (boot_event_store.GetBootEvent("post_decrypt_time_elapsed", &record)) { |