aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHansong Zhang <hsz@google.com>2018-02-09 14:16:59 -0800
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-02-26 23:52:39 +0000
commit310223acec54b32b170dfc2494cec88e4c5988c7 (patch)
tree67c8418218a7e13d1cf48b03cc3f12ee09789b01
parent8feb7403c2592afa645a61d6aefb3deba02f1266 (diff)
downloadbt-310223acec54b32b170dfc2494cec88e4c5988c7.tar.gz
DO NOT MERGE Truncate new line characters when adding string to config
Bug: 70808273 Test: test with a device with newline character in name Change-Id: I8729e12ad5851ee1ffbcb7c08e9a659f768ffc21 (cherry picked from commit dd9bbfc2458569d9fecf35f7503d1b89b4c69aa0)
-rw-r--r--osi/src/config.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/osi/src/config.cc b/osi/src/config.cc
index 10197210b..fc64d4746 100644
--- a/osi/src/config.cc
+++ b/osi/src/config.cc
@@ -34,6 +34,7 @@
#include "osi/include/allocator.h"
#include "osi/include/list.h"
#include "osi/include/log.h"
+#include "log/log.h"
typedef struct {
char* key;
@@ -217,17 +218,27 @@ void config_set_string(config_t* config, const char* section, const char* key,
list_append(config->sections, sec);
}
+ std::string value_string = value;
+ std::string value_no_newline;
+ size_t newline_position = value_string.find("\n");
+ if (newline_position != std::string::npos) {
+ android_errorWriteLog(0x534e4554, "70808273");
+ value_no_newline = value_string.substr(0, newline_position);
+ } else {
+ value_no_newline = value_string;
+ }
+
for (const list_node_t* node = list_begin(sec->entries);
node != list_end(sec->entries); node = list_next(node)) {
entry_t* entry = static_cast<entry_t*>(list_node(node));
if (!strcmp(entry->key, key)) {
osi_free(entry->value);
- entry->value = osi_strdup(value);
+ entry->value = osi_strdup(value_no_newline.c_str());
return;
}
}
- entry_t* entry = entry_new(key, value);
+ entry_t* entry = entry_new(key, value_no_newline.c_str());
list_append(sec->entries, entry);
}