diff options
author | Jin Qian | 2017-01-17 17:08:00 -0600 |
---|---|---|
committer | Jin Qian | 2017-01-17 17:45:05 -0600 |
commit | b00d5467d36a6f64f51b7a239bc426744440621d (patch) | |
tree | 5e70dafd74af685a729d01d8dfde76f8eb954e99 /storaged | |
parent | 27506fa41f7b07714b49eb3d36760a2f8c0708d0 (diff) | |
download | platform-system-core-b00d5467d36a6f64f51b7a239bc426744440621d.tar.gz platform-system-core-b00d5467d36a6f64f51b7a239bc426744440621d.tar.xz platform-system-core-b00d5467d36a6f64f51b7a239bc426744440621d.zip |
storaged: fix crash when cmdline is longer than 64 characters
Bug: 34331490
Change-Id: I40302f4d54b7d8fe4fc5ecbc76df42df68a35504
Diffstat (limited to 'storaged')
-rw-r--r-- | storaged/include/storaged.h | 2 | ||||
-rw-r--r-- | storaged/storaged_utils.cpp | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h index babe7ce0b..521cc9e29 100644 --- a/storaged/include/storaged.h +++ b/storaged/include/storaged.h | |||
@@ -67,7 +67,7 @@ struct disk_stats { | |||
67 | double io_avg; // average io_in_flight for accumulate calculations | 67 | double io_avg; // average io_in_flight for accumulate calculations |
68 | }; | 68 | }; |
69 | 69 | ||
70 | #define MMC_VER_STR_LEN ( 8 ) // maximum length of the MMC version string | 70 | #define MMC_VER_STR_LEN ( 9 ) // maximum length of the MMC version string, including NULL terminator |
71 | // minimum size of a ext_csd file | 71 | // minimum size of a ext_csd file |
72 | #define EXT_CSD_FILE_MIN_SIZE ( 1024 ) | 72 | #define EXT_CSD_FILE_MIN_SIZE ( 1024 ) |
73 | struct emmc_info { | 73 | struct emmc_info { |
diff --git a/storaged/storaged_utils.cpp b/storaged/storaged_utils.cpp index 27b9c6290..c845ac471 100644 --- a/storaged/storaged_utils.cpp +++ b/storaged/storaged_utils.cpp | |||
@@ -205,7 +205,7 @@ bool parse_emmc_ecsd(int ext_csd_fd, struct emmc_info* info) { | |||
205 | "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0" | 205 | "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0" |
206 | }; | 206 | }; |
207 | 207 | ||
208 | strncpy(info->mmc_ver, | 208 | strlcpy(info->mmc_ver, |
209 | (ext_csd_rev < (int)(sizeof(ver_str) / sizeof(ver_str[0]))) ? | 209 | (ext_csd_rev < (int)(sizeof(ver_str) / sizeof(ver_str[0]))) ? |
210 | ver_str[ext_csd_rev] : | 210 | ver_str[ext_csd_rev] : |
211 | "Unknown", | 211 | "Unknown", |
@@ -276,12 +276,12 @@ bool parse_task_info(uint32_t pid, struct task_info* info) { | |||
276 | // Get cmd string | 276 | // Get cmd string |
277 | std::string task_cmdline_path = android::base::StringPrintf(PROC_DIR "%u/cmdline", pid); | 277 | std::string task_cmdline_path = android::base::StringPrintf(PROC_DIR "%u/cmdline", pid); |
278 | if (!android::base::ReadFileToString(task_cmdline_path, &buffer)) return false; | 278 | if (!android::base::ReadFileToString(task_cmdline_path, &buffer)) return false; |
279 | strcpy(info->cmd, android::base::Trim(buffer).c_str()); | 279 | strlcpy(info->cmd, android::base::Trim(buffer).c_str(), sizeof(info->cmd)); |
280 | 280 | ||
281 | if (info->cmd[0] == '\0') { | 281 | if (info->cmd[0] == '\0') { |
282 | std::string task_comm_path = android::base::StringPrintf(PROC_DIR "%u/comm", pid); | 282 | std::string task_comm_path = android::base::StringPrintf(PROC_DIR "%u/comm", pid); |
283 | if (!android::base::ReadFileToString(task_comm_path, &buffer)) return false; | 283 | if (!android::base::ReadFileToString(task_comm_path, &buffer)) return false; |
284 | strcpy(info->cmd, android::base::Trim(buffer).c_str()); | 284 | strlcpy(info->cmd, android::base::Trim(buffer).c_str(), sizeof(info->cmd)); |
285 | } | 285 | } |
286 | 286 | ||
287 | // Get task start time | 287 | // Get task start time |