system/corennnnn
修訂 | f85554e12ff1a75d4bc47ac602c9201acc43ecc6 (tree) |
---|---|
時間 | 2016-07-30 00:24:28 |
作者 | James Hawkins <jhawkins@goog...> |
Commiter | James Hawkins |
bootstat: Fix a potential unhandled exception for malformed input.
In rare cases the hardware storage on the device may be hosed and return
garbage. Use ParseInt which handles bad input instead of stoi.
BUG: 29334139
Change-Id: I91aedc169df110bea8097775f73dda11def22311
(cherry picked from commit 4dded613b3aaee016adffd895edf3866426fc22a)
@@ -25,6 +25,7 @@ | ||
25 | 25 | #include <utility> |
26 | 26 | #include <android-base/file.h> |
27 | 27 | #include <android-base/logging.h> |
28 | +#include <android-base/parseint.h> | |
28 | 29 | #include "histogram_logger.h" |
29 | 30 | #include "uptime_parser.h" |
30 | 31 |
@@ -57,8 +58,10 @@ bool ParseRecordEventTime(const std::string& path, int32_t* uptime) { | ||
57 | 58 | |
58 | 59 | // Ignore existing bootstat records (which do not contain file content). |
59 | 60 | if (!content.empty()) { |
60 | - int32_t value = std::stoi(content); | |
61 | - bootstat::LogHistogram("bootstat_mtime_matches_content", value == *uptime); | |
61 | + int32_t value; | |
62 | + if (android::base::ParseInt(content.c_str(), &value)) { | |
63 | + bootstat::LogHistogram("bootstat_mtime_matches_content", value == *uptime); | |
64 | + } | |
62 | 65 | } |
63 | 66 | |
64 | 67 | return true; |
@@ -28,6 +28,7 @@ | ||
28 | 28 | #include <memory> |
29 | 29 | #include <string> |
30 | 30 | #include <android-base/logging.h> |
31 | +#include <android-base/parseint.h> | |
31 | 32 | #include <cutils/properties.h> |
32 | 33 | #include <log/log.h> |
33 | 34 | #include "boot_event_record_store.h" |
@@ -147,7 +148,10 @@ std::string CalculateBootCompletePrefix() { | ||
147 | 148 | std::string boot_complete_prefix = "boot_complete"; |
148 | 149 | |
149 | 150 | std::string build_date_str = GetProperty("ro.build.date.utc"); |
150 | - int32_t build_date = std::stoi(build_date_str); | |
151 | + int32_t build_date; | |
152 | + if (!android::base::ParseInt(build_date_str.c_str(), &build_date)) { | |
153 | + return std::string(); | |
154 | + } | |
151 | 155 | |
152 | 156 | BootEventRecordStore boot_event_store; |
153 | 157 | BootEventRecordStore::BootEventRecord record; |
@@ -171,6 +175,10 @@ void RecordBootComplete() { | ||
171 | 175 | // ota_boot_complete. The latter signifies that the device is booting after |
172 | 176 | // a system update. |
173 | 177 | std::string boot_complete_prefix = CalculateBootCompletePrefix(); |
178 | + if (boot_complete_prefix.empty()) { | |
179 | + // The system is hosed because the build date property could not be read. | |
180 | + return; | |
181 | + } | |
174 | 182 | |
175 | 183 | // post_decrypt_time_elapsed is only logged on encrypted devices. |
176 | 184 | if (boot_event_store.GetBootEvent("post_decrypt_time_elapsed", &record)) { |