dovecot-2.2: fts: If we fail while indexing headers, return fail...

dovecot at dovecot.org dovecot at dovecot.org
Tue Jun 2 16:54:59 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/dc4826a29990
changeset: 18794:dc4826a29990
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Jun 02 19:52:37 2015 +0300
description:
fts: If we fail while indexing headers, return failure immediately.

diffstat:

 src/plugins/fts/fts-build-mail.c |  30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diffs (99 lines):

diff -r f61345596ce6 -r dc4826a29990 src/plugins/fts/fts-build-mail.c
--- a/src/plugins/fts/fts-build-mail.c	Tue Jun 02 19:52:15 2015 +0300
+++ b/src/plugins/fts/fts-build-mail.c	Tue Jun 02 19:52:37 2015 +0300
@@ -97,13 +97,14 @@
 		fts_build_parse_content_disposition(ctx, hdr);
 }
 
-static void
+static int
 fts_build_unstructured_header(struct fts_mail_build_context *ctx,
 			      const struct message_header_line *hdr)
 {
 	const unsigned char *data = hdr->full_value;
 	unsigned char *buf = NULL;
 	unsigned int i;
+	int ret;
 
 	/* @UNSAFE: if there are any NULs, replace them with spaces */
 	for (i = 0; i < hdr->full_value_len; i++) {
@@ -118,8 +119,9 @@
 			buf[i] = data[i];
 		}
 	}
-	(void)fts_build_data(ctx, data, hdr->full_value_len, TRUE);
+	ret = fts_build_data(ctx, data, hdr->full_value_len, TRUE);
 	i_free(buf);
+	return ret;
 }
 
 static bool data_has_8bit(const unsigned char *data, size_t size)
@@ -150,14 +152,15 @@
 		ctx->cur_user_lang = fts_user_get_data_lang(ctx->update_ctx->backend->ns->user);
 }
 
-static void fts_build_mail_header(struct fts_mail_build_context *ctx,
-				  const struct message_block *block)
+static int fts_build_mail_header(struct fts_mail_build_context *ctx,
+				 const struct message_block *block)
 {
 	const struct message_header_line *hdr = block->hdr;
 	struct fts_backend_build_key key;
+	int ret;
 
 	if (hdr->eoh)
-		return;
+		return 0;
 
 	/* hdr->full_value is always set because we get the block from
 	   message_decoder */
@@ -173,11 +176,11 @@
 		fts_build_tokenized_hdr_update_lang(ctx, hdr);
 
 	if (!fts_backend_update_set_build_key(ctx->update_ctx, &key))
-		return;
+		return 0;
 
 	if (!message_header_is_address(hdr->name)) {
 		/* regular unstructured header */
-		fts_build_unstructured_header(ctx, hdr);
+		ret = fts_build_unstructured_header(ctx, hdr);
 	} else T_BEGIN {
 		/* message address. normalize it to give better
 		   search results. */
@@ -191,7 +194,7 @@
 		str = t_str_new(hdr->full_value_len);
 		message_address_write(str, addr);
 
-		(void)fts_build_data(ctx, str_data(str), str_len(str), TRUE);
+		ret = fts_build_data(ctx, str_data(str), str_len(str), TRUE);
 	} T_END;
 
 	if ((ctx->update_ctx->backend->flags &
@@ -199,10 +202,12 @@
 		/* index the header name itself */
 		key.hdr_name = "";
 		if (fts_backend_update_set_build_key(ctx->update_ctx, &key)) {
-			(void)fts_build_data(ctx, (const void *)hdr->name,
-					     strlen(hdr->name), TRUE);
+			if (fts_build_data(ctx, (const void *)hdr->name,
+					   strlen(hdr->name), TRUE) < 0)
+				ret = -1;
 		}
 	}
+	return ret;
 }
 
 static bool
@@ -543,7 +548,10 @@
 
 		if (block.hdr != NULL) {
 			fts_parse_mail_header(&ctx, &raw_block);
-			fts_build_mail_header(&ctx, &block);
+			if (fts_build_mail_header(&ctx, &block) < 0) {
+				ret = -1;
+				break;
+			}
 		} else if (block.size == 0) {
 			/* end of headers */
 		} else {


More information about the dovecot-cvs mailing list