dovecot-2.1: config: Don't crash strlist section contains a subs...

dovecot at dovecot.org dovecot at dovecot.org
Fri Sep 16 16:59:32 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/1a57526721d7
changeset: 13498:1a57526721d7
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Sep 16 12:08:49 2011 +0300
description:
config: Don't crash strlist section contains a subsection.

diffstat:

 src/config/config-parser.c |  25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diffs (61 lines):

diff -r 2795be14f37f -r 1a57526721d7 src/config/config-parser.c
--- a/src/config/config-parser.c	Fri Sep 16 11:59:15 2011 +0300
+++ b/src/config/config-parser.c	Fri Sep 16 12:08:49 2011 +0300
@@ -52,8 +52,8 @@
 	return NULL;
 }
 
-static void config_add_type(struct setting_parser_context *parser,
-			    const char *line, const char *section_name)
+static int config_add_type(struct setting_parser_context *parser,
+			   const char *line, const char *section_name)
 {
 	const struct setting_parser_info *info;
 	const char *p;
@@ -61,21 +61,28 @@
 	int ret;
 
 	info = settings_parse_get_prev_info(parser);
+	if (info == NULL) {
+		/* section inside strlist */
+		return -1;
+	}
 	if (info->type_offset == (size_t)-1)
-		return;
+		return 0;
 
 	str = t_str_new(256);
 	p = strchr(line, '=');
 	str_append_n(str, line, p-line);
 	str_append_c(str, SETTINGS_SEPARATOR);
 	str_append(str, p+1);
-	str_append_c(str, SETTINGS_SEPARATOR);
-	str_append(str, info_type_name_find(info));
+	if (info != NULL) {
+		str_append_c(str, SETTINGS_SEPARATOR);
+		str_append(str, info_type_name_find(info));
+	}
 	str_append_c(str, '=');
 	str_append(str, section_name);
 
 	ret = settings_parse_line(parser, str_c(str));
 	i_assert(ret > 0);
+	return 0;
 }
 
 static bool
@@ -106,8 +113,12 @@
 					key, NULL);
 				return -1;
 			}
-			if (section_name != NULL)
-				config_add_type(l->parser, line, section_name);
+			if (section_name != NULL) {
+				if (config_add_type(l->parser, line, section_name) < 0) {
+					ctx->error = "Section not allowed here";
+					return -1;
+				}
+			}
 		} else if (ret < 0) {
 			ctx->error = settings_parser_get_error(l->parser);
 			return -1;


More information about the dovecot-cvs mailing list