diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-03-19 15:32:17 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-03-19 15:32:17 -0400 |
commit | a7b46336eb5f1f7f734ac2d978c7ab17d1c870c0 (patch) | |
tree | 66cc240da6fb2cedc8dfa21adf9dc2183fd293f2 | |
parent | 60d14421363bdbeee337ba69b21640058a26a6bd (diff) | |
parent | 1827be0bd6a400f4b5970f5b37b1d2c8e83b6a3f (diff) | |
download | tor-a7b46336eb5f1f7f734ac2d978c7ab17d1c870c0.tar tor-a7b46336eb5f1f7f734ac2d978c7ab17d1c870c0.tar.gz |
Merge remote-tracking branch 'public/bug7950' into maint-0.2.4
-rw-r--r-- | changes/bug7950 | 4 | ||||
-rw-r--r-- | src/common/util.c | 19 | ||||
-rw-r--r-- | src/common/util.h | 7 | ||||
-rw-r--r-- | src/or/confparse.c | 5 |
4 files changed, 27 insertions, 8 deletions
diff --git a/changes/bug7950 b/changes/bug7950 new file mode 100644 index 000000000..e62cca07a --- /dev/null +++ b/changes/bug7950 @@ -0,0 +1,4 @@ + o Minor bugfixes: + - When rejecting a configuration because we were unable to parse a + quoted string, log an actual error message. Fix for bug 7950; + bugfix on 0.2.0.16-alpha. diff --git a/src/common/util.c b/src/common/util.c index 17fb9496c..2f1bc6171 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2428,10 +2428,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)? @@ -2505,12 +2508,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)) { diff --git a/src/common/util.h b/src/common/util.h index 8206a6d8a..fbf6d2bea 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -369,8 +369,11 @@ char *read_file_to_str(const char *filename, int flags, struct stat *stat_out) char *read_file_to_str_until_eof(int fd, size_t max_bytes_to_read, size_t *sz_out) ATTR_MALLOC; -const char *parse_config_line_from_str(const char *line, - char **key_out, char **value_out); +const char *parse_config_line_from_str_verbose(const char *line, + char **key_out, char **value_out, + const char **err_out); +#define parse_config_line_from_str(line,key_out,value_out) \ + parse_config_line_from_str_verbose((line),(key_out),(value_out),NULL) char *expand_filename(const char *filename); struct smartlist_t *tor_listdir(const char *dirname); int path_is_relative(const char *filename); diff --git a/src/or/confparse.c b/src/or/confparse.c index 717d4ac2a..98fde98e7 100644 --- a/src/or/confparse.c +++ b/src/or/confparse.c @@ -91,12 +91,15 @@ config_get_lines(const char *string, config_line_t **result, int extended) { config_line_t *list = NULL, **next; char *k, *v; + const char *parse_err; next = &list; do { k = v = NULL; - string = parse_config_line_from_str(string, &k, &v); + string = parse_config_line_from_str_verbose(string, &k, &v, &parse_err); if (!string) { + log_warn(LD_CONFIG, "Error while parsing configuration: %s", + parse_err?parse_err:"<unknown>"); config_free_lines(list); tor_free(k); tor_free(v); |