# HG changeset patch # User Timo Sirainen # Date 1453475677 -7200 # Node ID 487036a4b545e4fb374de3dbbb098267688d8282 # Parent d80976d7fec028d99d0b8bed49644b1cd1a0f681 fts-solr: If Solr lookup returns missing or invalid UID, fail the search. We were previously logging the error but still returning success. diff -r d80976d7fec0 -r 487036a4b545 src/plugins/fts-solr/solr-connection.c --- a/src/plugins/fts-solr/solr-connection.c Fri Jan 22 16:48:53 2016 +0200 +++ b/src/plugins/fts-solr/solr-connection.c Fri Jan 22 17:14:37 2016 +0200 @@ -28,7 +28,8 @@ SOLR_XML_CONTENT_STATE_SCORE, SOLR_XML_CONTENT_STATE_MAILBOX, SOLR_XML_CONTENT_STATE_NAMESPACE, - SOLR_XML_CONTENT_STATE_UIDVALIDITY + SOLR_XML_CONTENT_STATE_UIDVALIDITY, + SOLR_XML_CONTENT_STATE_ERROR }; struct solr_lookup_xml_context { @@ -237,15 +238,15 @@ return result; } -static void solr_lookup_add_doc(struct solr_lookup_xml_context *ctx) +static int solr_lookup_add_doc(struct solr_lookup_xml_context *ctx) { struct fts_score_map *score; struct solr_result *result; const char *box_id; if (ctx->uid == 0) { - i_error("fts_solr: Query didn't return uid"); - return; + i_error("fts_solr: uid missing from inside doc"); + return -1; } if (ctx->mailbox == NULL) { @@ -272,11 +273,16 @@ score->uid = ctx->uid; score->score = ctx->score; } + return 0; } static void solr_lookup_xml_end(void *context, const char *name ATTR_UNUSED) { struct solr_lookup_xml_context *ctx = context; + int ret; + + if (ctx->content_state == SOLR_XML_CONTENT_STATE_ERROR) + return; i_assert(ctx->depth >= (int)ctx->state); @@ -288,13 +294,17 @@ } if (ctx->depth == (int)ctx->state) { + ret = 0; if (ctx->state == SOLR_XML_RESPONSE_STATE_DOC) { T_BEGIN { - solr_lookup_add_doc(ctx); + ret = solr_lookup_add_doc(ctx); } T_END; } ctx->state--; - ctx->content_state = SOLR_XML_CONTENT_STATE_NONE; + if (ret < 0) + ctx->content_state = SOLR_XML_CONTENT_STATE_ERROR; + else + ctx->content_state = SOLR_XML_CONTENT_STATE_NONE; } ctx->depth--; } @@ -325,8 +335,11 @@ case SOLR_XML_CONTENT_STATE_NONE: break; case SOLR_XML_CONTENT_STATE_UID: - if (uint32_parse(str, len, &ctx->uid) < 0) - i_error("fts_solr: received invalid uid"); + if (uint32_parse(str, len, &ctx->uid) < 0 || ctx->uid == 0) { + i_error("fts_solr: received invalid uid '%s'", + t_strndup(str, len)); + ctx->content_state = SOLR_XML_CONTENT_STATE_ERROR; + } break; case SOLR_XML_CONTENT_STATE_SCORE: T_BEGIN { @@ -351,6 +364,8 @@ if (uint32_parse(str, len, &ctx->uidvalidity) < 0) i_error("fts_solr: received invalid uidvalidity"); break; + case SOLR_XML_CONTENT_STATE_ERROR: + break; } } @@ -436,7 +451,8 @@ conn->request_status = 0; http_client_wait(solr_http_client); - if (conn->request_status < 0) + if (conn->request_status < 0 || + solr_lookup_context.content_state == SOLR_XML_CONTENT_STATE_ERROR) return -1; parse_ret = solr_xml_parse(conn, "", 0, TRUE);