From 1cd98ae00896d7f436d3cca7f78570a740ae4f72 Mon Sep 17 00:00:00 2001 From: Palana Date: Fri, 27 Nov 2015 11:53:30 +0100 Subject: [PATCH] libobs/util: Fix config value line break unescaping Given a config file with some value "foo=\\n" querying the value of foo would return {'\\', '\n', 0}, instead of {'\\', 'n', 0} --- libobs/util/config-file.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/libobs/util/config-file.c b/libobs/util/config-file.c index a23d8d663..735afee72 100644 --- a/libobs/util/config-file.c +++ b/libobs/util/config-file.c @@ -117,15 +117,42 @@ static bool config_parse_string(struct lexer *lex, struct strref *ref, return success; } +static void unescape(struct dstr *str) +{ + char *read = str->array; + char *write = str->array; + + for (; *read; read++, write++) { + char cur = *read; + if (cur == '\\') { + char next = read[1]; + if (next == '\\') { + read++; + } else if (next == 'r') { + cur = '\r'; + read++; + } else if (next =='n') { + cur = '\n'; + read++; + } + } + + if (read != write) + *write = cur; + } + + if (read != write) + *write = '\0'; +} + static void config_add_item(struct darray *items, struct strref *name, struct strref *value) { struct config_item item; struct dstr item_value; dstr_init_copy_strref(&item_value, value); - dstr_replace(&item_value, "\\n", "\n"); - dstr_replace(&item_value, "\\r", "\r"); - dstr_replace(&item_value, "\\\\", "\\"); + + unescape(&item_value); item.name = bstrdup_n(name->array, name->len); item.value = item_value.array;