summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHansong Zhang <hsz@google.com>2018-02-09 14:16:59 -0800
committerAndreas Blaesius <andi@unlegacy-android.org>2018-04-14 14:02:00 +0200
commit178c0ff3a46a9a633822414ddeaed6aa0e536ba9 (patch)
tree6e527ce9666af5b6aaedd82a27bce2c61b254698
parent96e84cff3f765f89fdea5041e6394b6dfb466b5d (diff)
downloadandroid_system_bt-178c0ff3a46a9a633822414ddeaed6aa0e536ba9.tar.gz
android_system_bt-178c0ff3a46a9a633822414ddeaed6aa0e536ba9.tar.bz2
android_system_bt-178c0ff3a46a9a633822414ddeaed6aa0e536ba9.zip
DO NOT MERGE Truncate new line characters when adding string to config
[Reworked for C support] 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.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/osi/src/config.c b/osi/src/config.c
index 63a43f810..d3c89b23e 100644
--- a/osi/src/config.c
+++ b/osi/src/config.c
@@ -33,6 +33,7 @@
#include "osi/include/config.h"
#include "osi/include/list.h"
#include "osi/include/log.h"
+#include "log/log.h"
typedef struct {
char *key;
@@ -220,16 +221,38 @@ void config_set_string(config_t *config, const char *section, const char *key, c
}
}
+ char* value_string = (char*)value;
+ char* value_no_newline = NULL;
+ char* newline_ptr = strstr(value_string, "\n");
+ if (newline_ptr != NULL) {
+ android_errorWriteLog(0x534e4554, "70808273");
+ size_t newline_position = newline_ptr - value_string;
+ value_no_newline = osi_malloc(newline_position + 1);
+ if (value_no_newline == NULL) {
+ ALOGE("%s: Unable to allocate memory for value_no_newline", __func__);
+ return;
+ }
+
+ strncpy(value_no_newline, value_string, newline_position);
+ *(value_no_newline + newline_position) = '\0';
+ } 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 = list_node(node);
if (!strcmp(entry->key, key)) {
osi_free(entry->value);
- entry->value = osi_strdup(value);
+ entry->value = osi_strdup(value_no_newline);
+ if (newline_ptr != NULL)
+ osi_free(value_no_newline);
return;
}
}
- entry_t *entry = entry_new(key, value);
+ entry_t *entry = entry_new(key, value_no_newline);
+ if (newline_ptr != NULL)
+ osi_free(value_no_newline);
list_append(sec->entries, entry);
}