fs_mgr: Fix kernel command line parsing
Remove new line character ('\n') from the kernel command line after
reading from '/proc/cmdline'. This character is not contained in the
original string and is added as a result of reading (according to
kernel source codes [1]):
...
seq_puts(m, saved_command_line);
seq_putc(m, '\n');
...
As a result, this may corrupt the last argument of the string. For
example, if the last argument is 'androidboot.slot_suffix=_a', then the
target partition ('vendor_a\n') will not be found in fstab section of
the device tree.
[1] fs/proc/cmdline.c
Change-Id: I96a853f1f55f27d782afe2ca8c0b006a75368149
Signed-off-by: Ruslan Trofymenko <ruslan.trofymenko@linaro.org>
diff --git a/fs_mgr/fs_mgr_boot_config.cpp b/fs_mgr/fs_mgr_boot_config.cpp
index 733ad55..abece4d 100644
--- a/fs_mgr/fs_mgr_boot_config.cpp
+++ b/fs_mgr/fs_mgr_boot_config.cpp
@@ -81,6 +81,9 @@
bool fs_mgr_get_boot_config_from_kernel_cmdline(const std::string& key, std::string* out_val) {
std::string cmdline;
if (!android::base::ReadFileToString("/proc/cmdline", &cmdline)) return false;
+ if (!cmdline.empty() && cmdline.back() == '\n') {
+ cmdline.pop_back();
+ }
return fs_mgr_get_boot_config_from_kernel(cmdline, key, out_val);
}