]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: If we fail while indexing headers, return failure immediately.
authorTimo Sirainen <tss@iki.fi>
Tue, 2 Jun 2015 16:52:37 +0000 (19:52 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 2 Jun 2015 16:52:37 +0000 (19:52 +0300)
src/plugins/fts/fts-build-mail.c

index 9c97a63bc0241f7338769ed22dbc339e2c1a96be..55838af2788ea7310d807b93b484f95b3f495938 100644 (file)
@@ -97,13 +97,14 @@ static void fts_parse_mail_header(struct fts_mail_build_context *ctx,
                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 @@ fts_build_unstructured_header(struct fts_mail_build_context *ctx,
                        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 @@ fts_build_tokenized_hdr_update_lang(struct fts_mail_build_context *ctx,
                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 @@ static void fts_build_mail_header(struct fts_mail_build_context *ctx,
                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 @@ static void fts_build_mail_header(struct fts_mail_build_context *ctx,
                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 @@ static void fts_build_mail_header(struct fts_mail_build_context *ctx,
                /* 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 @@ fts_build_mail_real(struct fts_backend_update_context *update_ctx,
 
                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 {