From f55965591206c8b5d8044f13a3ac1e9a48626394 Mon Sep 17 00:00:00 2001 From: Bowgo Tsai Date: Thu, 13 Jul 2017 15:05:08 +0800 Subject: [PATCH] fs_mgr: trim the terminating '\0' when reading from device tree Bug: 63637343 Test: boot device Change-Id: I35ead1ad852493f7f92bdb6c87617fde57b3b0be --- fs_mgr/fs_mgr_boot_config.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs_mgr/fs_mgr_boot_config.cpp b/fs_mgr/fs_mgr_boot_config.cpp index ab5beed81..911766752 100644 --- a/fs_mgr/fs_mgr_boot_config.cpp +++ b/fs_mgr/fs_mgr_boot_config.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include #include #include @@ -51,9 +53,11 @@ bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) { // lastly, check the device tree if (is_dt_compatible()) { std::string file_name = kAndroidDtDir + "/" + key; - // DT entries terminate with '\0' but so do the properties if (android::base::ReadFileToString(file_name, out_val)) { - return true; + if (!out_val->empty()) { + out_val->pop_back(); // Trims the trailing '\0' out. + return true; + } } }