storaged: fix crash when cmdline is longer than 64 characters

Bug: 34331490
Change-Id: I40302f4d54b7d8fe4fc5ecbc76df42df68a35504
diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h
index babe7ce..521cc9e 100644
--- a/storaged/include/storaged.h
+++ b/storaged/include/storaged.h
@@ -67,7 +67,7 @@
     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 {
diff --git a/storaged/storaged_utils.cpp b/storaged/storaged_utils.cpp
index 27b9c62..c845ac4 100644
--- a/storaged/storaged_utils.cpp
+++ b/storaged/storaged_utils.cpp
@@ -205,7 +205,7 @@
         "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 @@
     // 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