From 01facbcf9762e93010744edfa9bd04a46f95be6e Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Fri, 9 Feb 2018 15:23:07 -0800 Subject: [PATCH] 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: Ie7e0b5d93047bc12a9cb84cc15f7f68f38f36441 --- osi/src/config.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/osi/src/config.c b/osi/src/config.c index 345f907d5..9145ce67f 100644 --- a/osi/src/config.c +++ b/osi/src/config.c @@ -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; @@ -216,16 +217,28 @@ void config_set_string(config_t *config, const char *section, const char *key, c list_append(config->sections, sec); } + size_t value_len = strlen(value); + char *value_no_newline = osi_strdup(value); + for (size_t i = 0; i < value_len; i++) { + if (value[i] == '\n') { + android_errorWriteLog(0x534e4554, "70808273"); + value_no_newline[i] = '\0'; + break; + } + } + for (const list_node_t *node = list_begin(sec->entries); node != list_end(sec->entries); node = list_next(node)) { entry_t *entry = list_node(node); if (!strcmp(entry->key, key)) { osi_free(entry->value); - entry->value = osi_strdup(value); + entry->value = osi_strdup(value_no_newline); + osi_free(value_no_newline); return; } } - entry_t *entry = entry_new(key, value); + entry_t *entry = entry_new(key, value_no_newline); + osi_free(value_no_newline); list_append(sec->entries, entry); } -- 2.11.0