summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJin Qian2017-03-14 13:20:02 -0500
committerJin Qian2017-03-14 13:20:02 -0500
commit9b1aeae7306cfd19e0c4704db5807edf8c0c14b7 (patch)
tree332f5471e529fd12e5f7eff2c838dc558e0ff1b0 /storaged
parent4f5206d2ea0a481929b33204eb08c657fd660e8f (diff)
downloadplatform-system-core-9b1aeae7306cfd19e0c4704db5807edf8c0c14b7.tar.gz
platform-system-core-9b1aeae7306cfd19e0c4704db5807edf8c0c14b7.tar.xz
platform-system-core-9b1aeae7306cfd19e0c4704db5807edf8c0c14b7.zip
storaged: replace string functions that can throw exception
android coding style doesn't allow exception handling which leads to crash when any function throws exception. Replace such functions in storaged to gracefully handle invalid inputs. Test: adb shell dumpsys storaged --hours N --time_window 300 Bug: 36131658 Change-Id: I36be1b49c4d9977a01d1bd4c9ca57d49322d95f4
Diffstat (limited to 'storaged')
-rw-r--r--storaged/storaged_service.cpp13
-rw-r--r--storaged/storaged_uid_monitor.cpp36
2 files changed, 27 insertions, 22 deletions
diff --git a/storaged/storaged_service.cpp b/storaged/storaged_service.cpp
index f968ed75f..c099048ba 100644
--- a/storaged/storaged_service.cpp
+++ b/storaged/storaged_service.cpp
@@ -18,6 +18,8 @@
18 18
19#include <vector> 19#include <vector>
20 20
21#include <android-base/parseint.h>
22#include <android-base/parsedouble.h>
21#include <binder/IBinder.h> 23#include <binder/IBinder.h>
22#include <binder/IInterface.h> 24#include <binder/IInterface.h>
23 25
@@ -29,6 +31,8 @@
29#include <storaged.h> 31#include <storaged.h>
30#include <storaged_service.h> 32#include <storaged_service.h>
31 33
34using namespace android::base;
35
32extern storaged_t storaged; 36extern storaged_t storaged;
33 37
34std::vector<struct uid_info> BpStoraged::dump_uids(const char* /*option*/) { 38std::vector<struct uid_info> BpStoraged::dump_uids(const char* /*option*/) {
@@ -97,19 +101,22 @@ status_t Storaged::dump(int fd, const Vector<String16>& args) {
97 if (arg == String16("--hours")) { 101 if (arg == String16("--hours")) {
98 if (++i >= args.size()) 102 if (++i >= args.size())
99 break; 103 break;
100 hours = std::stod(String8(args[i]).string()); 104 if(!ParseDouble(String8(args[i]).c_str(), &hours))
105 return BAD_VALUE;
101 continue; 106 continue;
102 } 107 }
103 if (arg == String16("--time_window")) { 108 if (arg == String16("--time_window")) {
104 if (++i >= args.size()) 109 if (++i >= args.size())
105 break; 110 break;
106 time_window = std::stoi(String8(args[i]).string()); 111 if(!ParseInt(String8(args[i]).c_str(), &time_window))
112 return BAD_VALUE;
107 continue; 113 continue;
108 } 114 }
109 if (arg == String16("--threshold")) { 115 if (arg == String16("--threshold")) {
110 if (++i >= args.size()) 116 if (++i >= args.size())
111 break; 117 break;
112 threshold = std::stoll(String8(args[i]).string()); 118 if(!ParseUint(String8(args[i]).c_str(), &threshold))
119 return BAD_VALUE;
113 continue; 120 continue;
114 } 121 }
115 if (arg == String16("--force")) { 122 if (arg == String16("--force")) {
diff --git a/storaged/storaged_uid_monitor.cpp b/storaged/storaged_uid_monitor.cpp
index 8bb6bf30b..5bb98e1e8 100644
--- a/storaged/storaged_uid_monitor.cpp
+++ b/storaged/storaged_uid_monitor.cpp
@@ -25,6 +25,7 @@
25#include <android-base/file.h> 25#include <android-base/file.h>
26#include <android-base/logging.h> 26#include <android-base/logging.h>
27#include <android-base/macros.h> 27#include <android-base/macros.h>
28#include <android-base/parseint.h>
28#include <android-base/strings.h> 29#include <android-base/strings.h>
29#include <android-base/stringprintf.h> 30#include <android-base/stringprintf.h>
30#include <log/log_event_list.h> 31#include <log/log_event_list.h>
@@ -59,12 +60,12 @@ std::unordered_map<uint32_t, struct uid_info> uid_monitor::get_uid_io_stats_lock
59{ 60{
60 std::unordered_map<uint32_t, struct uid_info> uid_io_stats; 61 std::unordered_map<uint32_t, struct uid_info> uid_io_stats;
61 std::string buffer; 62 std::string buffer;
62 if (!android::base::ReadFileToString(UID_IO_STATS_PATH, &buffer)) { 63 if (!ReadFileToString(UID_IO_STATS_PATH, &buffer)) {
63 PLOG_TO(SYSTEM, ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed"; 64 PLOG_TO(SYSTEM, ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed";
64 return uid_io_stats; 65 return uid_io_stats;
65 } 66 }
66 67
67 std::vector<std::string> io_stats = android::base::Split(buffer, "\n"); 68 std::vector<std::string> io_stats = Split(buffer, "\n");
68 struct uid_info u; 69 struct uid_info u;
69 bool refresh_uid = false; 70 bool refresh_uid = false;
70 71
@@ -72,26 +73,23 @@ std::unordered_map<uint32_t, struct uid_info> uid_monitor::get_uid_io_stats_lock
72 if (io_stats[i].empty()) { 73 if (io_stats[i].empty()) {
73 continue; 74 continue;
74 } 75 }
75 std::vector<std::string> fields = android::base::Split(io_stats[i], " "); 76 std::vector<std::string> fields = Split(io_stats[i], " ");
76 if (fields.size() < 9) { 77 if (fields.size() < 11 ||
77 LOG_TO(SYSTEM, WARNING) << "Invalid io stats: \"" 78 !ParseUint(fields[0], &u.uid) ||
79 !ParseUint(fields[1], &u.io[FOREGROUND].rchar) ||
80 !ParseUint(fields[2], &u.io[FOREGROUND].wchar) ||
81 !ParseUint(fields[3], &u.io[FOREGROUND].read_bytes) ||
82 !ParseUint(fields[4], &u.io[FOREGROUND].write_bytes) ||
83 !ParseUint(fields[5], &u.io[BACKGROUND].rchar) ||
84 !ParseUint(fields[6], &u.io[BACKGROUND].wchar) ||
85 !ParseUint(fields[7], &u.io[BACKGROUND].read_bytes) ||
86 !ParseUint(fields[8], &u.io[BACKGROUND].write_bytes) ||
87 !ParseUint(fields[9], &u.io[FOREGROUND].fsync) ||
88 !ParseUint(fields[10], &u.io[BACKGROUND].fsync)) {
89 LOG_TO(SYSTEM, WARNING) << "Invalid I/O stats: \""
78 << io_stats[i] << "\""; 90 << io_stats[i] << "\"";
79 continue; 91 continue;
80 } 92 }
81 u.uid = stoul(fields[0]);
82 u.io[FOREGROUND].rchar = stoull(fields[1]);
83 u.io[FOREGROUND].wchar = stoull(fields[2]);
84 u.io[FOREGROUND].read_bytes = stoull(fields[3]);
85 u.io[FOREGROUND].write_bytes = stoull(fields[4]);
86 u.io[BACKGROUND].rchar = stoull(fields[5]);
87 u.io[BACKGROUND].wchar = stoull(fields[6]);
88 u.io[BACKGROUND].read_bytes = stoull(fields[7]);
89 u.io[BACKGROUND].write_bytes = stoull(fields[8]);
90
91 if (fields.size() == 11) {
92 u.io[FOREGROUND].fsync = stoull(fields[9]);
93 u.io[BACKGROUND].fsync = stoull(fields[10]);
94 }
95 93
96 if (last_uid_io_stats.find(u.uid) == last_uid_io_stats.end()) { 94 if (last_uid_io_stats.find(u.uid) == last_uid_io_stats.end()) {
97 refresh_uid = true; 95 refresh_uid = true;