• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修訂f85554e12ff1a75d4bc47ac602c9201acc43ecc6 (tree)
時間2016-07-30 00:24:28
作者James Hawkins <jhawkins@goog...>
CommiterJames Hawkins

Log Message

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)

Change Summary

差異

--- a/bootstat/boot_event_record_store.cpp
+++ b/bootstat/boot_event_record_store.cpp
@@ -25,6 +25,7 @@
2525 #include <utility>
2626 #include <android-base/file.h>
2727 #include <android-base/logging.h>
28+#include <android-base/parseint.h>
2829 #include "histogram_logger.h"
2930 #include "uptime_parser.h"
3031
@@ -57,8 +58,10 @@ bool ParseRecordEventTime(const std::string& path, int32_t* uptime) {
5758
5859 // Ignore existing bootstat records (which do not contain file content).
5960 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+ }
6265 }
6366
6467 return true;
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -28,6 +28,7 @@
2828 #include <memory>
2929 #include <string>
3030 #include <android-base/logging.h>
31+#include <android-base/parseint.h>
3132 #include <cutils/properties.h>
3233 #include <log/log.h>
3334 #include "boot_event_record_store.h"
@@ -147,7 +148,10 @@ std::string CalculateBootCompletePrefix() {
147148 std::string boot_complete_prefix = "boot_complete";
148149
149150 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+ }
151155
152156 BootEventRecordStore boot_event_store;
153157 BootEventRecordStore::BootEventRecord record;
@@ -171,6 +175,10 @@ void RecordBootComplete() {
171175 // ota_boot_complete. The latter signifies that the device is booting after
172176 // a system update.
173177 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+ }
174182
175183 // post_decrypt_time_elapsed is only logged on encrypted devices.
176184 if (boot_event_store.GetBootEvent("post_decrypt_time_elapsed", &record)) {