dovecot-1.2: message address parser: Handle errors better, fix c...

dovecot at dovecot.org dovecot at dovecot.org
Sun Sep 7 19:25:33 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/99704b6b8dde
changeset: 8167:99704b6b8dde
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Sep 07 19:25:29 2008 +0300
description:
message address parser: Handle errors better, fix crash in previous change.

diffstat:

1 file changed, 23 insertions(+), 13 deletions(-)
src/lib-mail/message-address.c |   36 +++++++++++++++++++++++-------------

diffs (68 lines):

diff -r a1f6c93afbc2 -r 99704b6b8dde src/lib-mail/message-address.c
--- a/src/lib-mail/message-address.c	Sun Sep 07 17:59:22 2008 +0300
+++ b/src/lib-mail/message-address.c	Sun Sep 07 19:25:29 2008 +0300
@@ -172,6 +172,15 @@ static int parse_addr_spec(struct messag
 			p_strdup(ctx->pool, str_c(ctx->parser.last_comment));
 	}
 	return ret;
+}
+
+static void add_fixed_address(struct message_address_parser_context *ctx)
+{
+	if (ctx->addr.mailbox == NULL)
+		ctx->addr.mailbox = !ctx->fill_missing ? "" : "MISSING_MAILBOX";
+	if (ctx->addr.domain == NULL)
+		ctx->addr.domain = !ctx->fill_missing ? "" : "MISSING_DOMAIN";
+	add_address(ctx);
 }
 
 static int parse_mailbox(struct message_address_parser_context *ctx)
@@ -191,16 +200,7 @@ static int parse_mailbox(struct message_
 			return -1;
 	}
 
-	if (ctx->addr.mailbox == NULL) {
-		ctx->addr.mailbox = !ctx->fill_missing ? "" :
-			p_strdup(ctx->pool, "MISSING_MAILBOX");
-	}
-	if (ctx->addr.domain == NULL) {
-		ctx->addr.domain = !ctx->fill_missing ? "" :
-			p_strdup(ctx->pool, "MISSING_DOMAIN");
-	}
-	add_address(ctx);
-
+	add_fixed_address(ctx);
 	return ret;
 }
 
@@ -289,6 +289,7 @@ message_address_parse_real(pool_t pool, 
 			   unsigned int max_addresses, bool fill_missing)
 {
 	struct message_address_parser_context ctx;
+	int ret;
 
 	memset(&ctx, 0, sizeof(ctx));
 
@@ -297,10 +298,19 @@ message_address_parse_real(pool_t pool, 
 	ctx.str = t_str_new(128);
 	ctx.fill_missing = fill_missing;
 
-	rfc822_skip_lwsp(&ctx.parser);
-
-	if (parse_address_list(&ctx, max_addresses) < 0)
+	ret = rfc822_skip_lwsp(&ctx.parser);
+	if (ret == 0) {
+		/* no addresses */
+		return NULL;
+	}
+	if (ret < 0 || parse_address_list(&ctx, max_addresses) < 0) {
+		if (ctx.first_addr == NULL) {
+			/* we had some input - we'll have to return something
+			   so that we can set invalid_syntax */
+			add_fixed_address(&ctx);
+		}
 		ctx.first_addr->invalid_syntax = TRUE;
+	}
 	return ctx.first_addr;
 }
 


More information about the dovecot-cvs mailing list