summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo.ingls@gmail.com <paolo.ingls@gmail.com>2016-09-26 23:25:16 +0200
committerNick Mathewson <nickm@torproject.org>2016-10-11 09:25:22 -0400
commitab78a4df93d1aed26cb13343cdd012c8309a206f (patch)
treeadd974947f715d6c493a1fe42e832f81c50e7591
parent332865872846c38b518adc4189ca0aa5eaab1378 (diff)
downloadtor-ab78a4df93d1aed26cb13343cdd012c8309a206f.tar.gz
tor-ab78a4df93d1aed26cb13343cdd012c8309a206f.zip
torrc parsing b0rks on carriage-return
(Specifically, carriage return after a quoted value in a config line. Fixes bug 19167; bugfix on 0.2.0.16-alpha when we introduced support for quoted values. Unit tests, changes file, and this parenthetical by nickm.)
-rw-r--r--changes/bug191674
-rw-r--r--src/common/util.c2
-rw-r--r--src/test/test_util.c31
3 files changed, 37 insertions, 0 deletions
diff --git a/changes/bug19167 b/changes/bug19167
new file mode 100644
index 0000000000..4a6c22dfc6
--- /dev/null
+++ b/changes/bug19167
@@ -0,0 +1,4 @@
+ o Minor bugfixes (configuration):
+ - When parsing quoted configuration values from the torrc file,
+ handle windows line endings correctly. Fixes bug 19167; bugfix on
+ 0.2.0.16-alpha. Patch from "Pingl".
diff --git a/src/common/util.c b/src/common/util.c
index 259ff8756f..d1c87d3e85 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -3079,6 +3079,8 @@ parse_config_line_from_str_verbose(const char *line, char **key_out,
}
while (*line == ' ' || *line == '\t')
++line;
+ if (*line == '\r' && *(++line) == '\n')
+ ++line;
if (*line && *line != '#' && *line != '\n') {
if (err_out)
*err_out = "Excess data after quoted string";
diff --git a/src/test/test_util.c b/src/test/test_util.c
index d2152dd698..8d5dce3983 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1642,6 +1642,36 @@ test_util_config_line_escaped_content(void *arg)
tor_free(v);
}
+static void
+test_util_config_line_crlf(void *arg)
+{
+ char *k=NULL, *v=NULL;
+ const char *err = NULL;
+ (void)arg;
+ const char *str =
+ "Hello world\r\n"
+ "Hello \"nice big world\"\r\n";
+
+ str = parse_config_line_from_str_verbose(str, &k, &v, &err);
+ tt_assert(str);
+ tt_str_op(k,OP_EQ,"Hello");
+ tt_str_op(v,OP_EQ,"world");
+ tt_assert(!err);
+ tor_free(k); tor_free(v);
+
+ str = parse_config_line_from_str_verbose(str, &k, &v, &err);
+ tt_assert(str);
+ tt_str_op(k,OP_EQ,"Hello");
+ tt_str_op(v,OP_EQ,"nice big world");
+ tt_assert(!err);
+ tor_free(k); tor_free(v);
+ tt_str_op(str,OP_EQ, "");
+
+ done:
+ tor_free(k); tor_free(v);
+}
+
+
#ifndef _WIN32
static void
test_util_expand_filename(void *arg)
@@ -5609,6 +5639,7 @@ struct testcase_t util_tests[] = {
UTIL_LEGACY(config_line_quotes),
UTIL_LEGACY(config_line_comment_character),
UTIL_LEGACY(config_line_escaped_content),
+ UTIL_LEGACY(config_line_crlf),
UTIL_LEGACY_NO_WIN(expand_filename),
UTIL_LEGACY(escape_string_socks),
UTIL_LEGACY(string_is_key_value),