Truncate new line characters when adding string to config

Bug: 70808273
Test: test with a device with newline character in name
Change-Id: I20cf26351cf2dae65a6ba4766e0dbfd0c721ddb5
diff --git a/system/osi/src/config.cc b/system/osi/src/config.cc
index 9bf76df..93d7417 100644
--- a/system/osi/src/config.cc
+++ b/system/osi/src/config.cc
@@ -17,6 +17,7 @@
  ******************************************************************************/
 
 #include "osi/include/config.h"
+#include "log/log.h"
 
 #include <base/files/file_path.h>
 #include <base/logging.h>
@@ -155,14 +156,23 @@
     sec = std::prev(config->sections.end());
   }
 
+  std::string value_no_newline;
+  size_t newline_position = value.find("\n");
+  if (newline_position != std::string::npos) {
+    android_errorWriteLog(0x534e4554, "70808273");
+    value_no_newline = value.substr(0, newline_position);
+  } else {
+    value_no_newline = value;
+  }
+
   for (entry_t& entry : sec->entries) {
     if (entry.key == key) {
-      entry.value = value;
+      entry.value = value_no_newline;
       return;
     }
   }
 
-  sec->entries.emplace_back(entry_t{.key = key, .value = value});
+  sec->entries.emplace_back(entry_t{.key = key, .value = value_no_newline});
 }
 
 bool config_remove_section(config_t* config, const std::string& section) {