storaged: fix crash when cmdline is longer than 64 characters

Bug: 34331490
Change-Id: I40302f4d54b7d8fe4fc5ecbc76df42df68a35504
This commit is contained in:
Jin Qian 2017-01-17 15:08:00 -08:00
parent 27506fa41f
commit b00d5467d3
2 changed files with 4 additions and 4 deletions

View File

@ -67,7 +67,7 @@ struct disk_stats {
double io_avg; // average io_in_flight for accumulate calculations
};
#define MMC_VER_STR_LEN ( 8 ) // maximum length of the MMC version string
#define MMC_VER_STR_LEN ( 9 ) // maximum length of the MMC version string, including NULL terminator
// minimum size of a ext_csd file
#define EXT_CSD_FILE_MIN_SIZE ( 1024 )
struct emmc_info {

View File

@ -205,7 +205,7 @@ bool parse_emmc_ecsd(int ext_csd_fd, struct emmc_info* info) {
"4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0"
};
strncpy(info->mmc_ver,
strlcpy(info->mmc_ver,
(ext_csd_rev < (int)(sizeof(ver_str) / sizeof(ver_str[0]))) ?
ver_str[ext_csd_rev] :
"Unknown",
@ -276,12 +276,12 @@ bool parse_task_info(uint32_t pid, struct task_info* info) {
// Get cmd string
std::string task_cmdline_path = android::base::StringPrintf(PROC_DIR "%u/cmdline", pid);
if (!android::base::ReadFileToString(task_cmdline_path, &buffer)) return false;
strcpy(info->cmd, android::base::Trim(buffer).c_str());
strlcpy(info->cmd, android::base::Trim(buffer).c_str(), sizeof(info->cmd));
if (info->cmd[0] == '\0') {
std::string task_comm_path = android::base::StringPrintf(PROC_DIR "%u/comm", pid);
if (!android::base::ReadFileToString(task_comm_path, &buffer)) return false;
strcpy(info->cmd, android::base::Trim(buffer).c_str());
strlcpy(info->cmd, android::base::Trim(buffer).c_str(), sizeof(info->cmd));
}
// Get task start time