aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-03-19 15:32:44 -0400
committerNick Mathewson <nickm@torproject.org>2013-03-19 15:32:44 -0400
commitacbfc9c8cc2c24adb610d391cb2b83d7cbc11719 (patch)
tree831e14a7b6c842b50b0ec928f8f84ff9e7fddb5c /src/common/util.c
parent60fd08f40be9bfe3e53de4e22b66f25451206f96 (diff)
parenta7b46336eb5f1f7f734ac2d978c7ab17d1c870c0 (diff)
downloadtor-acbfc9c8cc2c24adb610d391cb2b83d7cbc11719.tar
tor-acbfc9c8cc2c24adb610d391cb2b83d7cbc11719.tar.gz
Merge remote-tracking branch 'origin/maint-0.2.4'
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 144f472d9..d297cb2db 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2501,10 +2501,13 @@ unescape_string(const char *s, char **result, size_t *size_out)
* key portion and *<b>value_out</b> to a new string holding the value portion
* of the line, and return a pointer to the start of the next line. If we run
* out of data, return a pointer to the end of the string. If we encounter an
- * error, return NULL.
+ * error, return NULL and set *<b>err_out</b> (if provided) to an error
+ * message.
*/
const char *
-parse_config_line_from_str(const char *line, char **key_out, char **value_out)
+parse_config_line_from_str_verbose(const char *line, char **key_out,
+ char **value_out,
+ const char **err_out)
{
/* I believe the file format here is supposed to be:
FILE = (EMPTYLINE | LINE)* (EMPTYLASTLINE | LASTLINE)?
@@ -2578,12 +2581,18 @@ parse_config_line_from_str(const char *line, char **key_out, char **value_out)
/* Find the end of the line. */
if (*line == '\"') { // XXX No continuation handling is done here
- if (!(line = unescape_string(line, value_out, NULL)))
- return NULL;
+ if (!(line = unescape_string(line, value_out, NULL))) {
+ if (err_out)
+ *err_out = "Invalid escape sequence in quoted string";
+ return NULL;
+ }
while (*line == ' ' || *line == '\t')
++line;
- if (*line && *line != '#' && *line != '\n')
+ if (*line && *line != '#' && *line != '\n') {
+ if (err_out)
+ *err_out = "Excess data after quoted string";
return NULL;
+ }
} else {
/* Look for the end of the line. */
while (*line && *line != '\n' && (*line != '#' || continuation)) {