From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id IEbhNUIbjGKPLQEAbAwnHQ (envelope-from ) for ; Tue, 24 May 2022 01:39:46 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id mBenNUIbjGIhdgAAauVa8A (envelope-from ) for ; Tue, 24 May 2022 01:39:46 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A95B639B1D for ; Tue, 24 May 2022 01:39:46 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 251625F7AD; Mon, 23 May 2022 23:39:17 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id B481D5F795 for ; Mon, 23 May 2022 23:39:14 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 0F8275FC0D; Mon, 23 May 2022 19:39:13 -0400 (EDT) Received: (nullmailer pid 3506941 invoked by uid 1000); Mon, 23 May 2022 23:39:02 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/8] lib/message: catch exceptions in _n_m_add_term Date: Mon, 23 May 2022 20:38:55 -0300 Message-Id: <20220523233901.3506880-3-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220523233901.3506880-1-david@tethera.net> References: <20220523233901.3506880-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: CFP53JQMID25NIM6353U4EMKIB4SJQSQ X-Message-ID-Hash: CFP53JQMID25NIM6353U4EMKIB4SJQSQ X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653349186; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=m8dN86Ppvqp8UchJeLRcZHLJbD8UJQ0IRHPnf5nJ3DM=; b=rU6TTJ4xzJr5jmv3mjVH5FVBqfMS0VcchB6XoqQji6VJ4+khpAmv11T0g5x0/P4E0jIfbN mmH1Oa7hVV0F5u87jERsVQep1VYk1oYU8KHc23meCaglqO7bBCiAe2gyC0jkLs7dYlcnyX YlAJFFEFL/1J/lt337psEPR7eKYMEIgf+NBZX0Q8GI/K6i40INDZH7Czm4wtle2jIy5kCl 69LeiqSgavCf9SwANT3/gSwBQoksk7Mo0XJjHs49oiXcQ9LojItC/0bT3b81IVx/4spq7r ymq550bzHd8p2r6JVBIKg+cBo9U5hCrJOJXG6w/mTeQKz0/hc93FSDX2bA4sjw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653349186; a=rsa-sha256; cv=none; b=BpoPXFEb4dqJMB5crklIu6wYOlm0tECwXlHRTZArloMayCIachnsFbzxoUcYufSPaoys59 GTOMfeGase5g9M6IlmvbenUQGgBKSupPy41mkI0Xed5nlgE6AGpH7Z9wZQS7hKePhAwxw/ VKwbubCvdHyq29evqA93uBe1nZPopIL6WerpGLMZo5fciWrNLDPzarj9ZuAOjMC+dUeOoZ zv9Xk4q9g9v0M4YGvIvF3Az4Ecy1TsR2hq1BdCWnLo3yZQF3LJHtlwAUdLYlqZg9hSrAQc IW1yCQzv+AgD+9uduy/d8f3EwG+BBkL0dlU8lVa8UonbbjvSnoM9A+aGQ3OpKw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.02 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A95B639B1D X-Spam-Score: -1.02 X-Migadu-Scanner: scn1.migadu.com X-TUID: nUR/3KCSRRUl Some code movement is needed to make sure the cache is only invalidated when the Xapian operation succeeds. --- lib/message.cc | 27 +++++++++++++++++---------- test/T566-lib-message.sh | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 63b216b6..bf3a3419 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -1489,24 +1489,30 @@ _notmuch_message_add_term (notmuch_message_t *message, { char *term; + notmuch_private_status_t status = NOTMUCH_PRIVATE_STATUS_SUCCESS; if (value == NULL) return NOTMUCH_PRIVATE_STATUS_NULL_POINTER; term = talloc_asprintf (message, "%s%s", _find_prefix (prefix_name), value); + if (strlen (term) > NOTMUCH_TERM_MAX) { + status = NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG; + goto DONE; + } - if (strlen (term) > NOTMUCH_TERM_MAX) - return NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG; - - message->doc.add_term (term, 0); - message->modified = true; + try { + message->doc.add_term (term, 0); + message->modified = true; + _notmuch_message_invalidate_metadata (message, prefix_name); + } catch (Xapian::Error &error) { + LOG_XAPIAN_EXCEPTION (message, error); + status = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION; + } + DONE: talloc_free (term); - - _notmuch_message_invalidate_metadata (message, prefix_name); - - return NOTMUCH_PRIVATE_STATUS_SUCCESS; + return status; } /* Parse 'text' and add a term to 'message' for each parsed word. Each @@ -1570,11 +1576,12 @@ _notmuch_message_remove_term (notmuch_message_t *message, try { message->doc.remove_term (term); message->modified = true; - } catch (const Xapian::InvalidArgumentError) { + } catch (const Xapian::InvalidArgumentError &error) { /* We'll let the philosophers try to wrestle with the * question of whether failing to remove that which was not * there in the first place is failure. For us, we'll silently * consider it all good. */ + LOG_XAPIAN_EXCEPTION (message, error); } talloc_free (term); diff --git a/test/T566-lib-message.sh b/test/T566-lib-message.sh index 8b61d182..08ab2765 100755 --- a/test/T566-lib-message.sh +++ b/test/T566-lib-message.sh @@ -305,6 +305,23 @@ cat < EXPECTED EOF test_expect_equal_file EXPECTED OUTPUT +test_begin_subtest "_notmuch_message_add_term catches exceptions" +cat c_head0 - c_tail <<'EOF' | test_private_C ${MAIL_DIR} + { + notmuch_private_status_t status; + /* This relies on Xapian throwing an exception for adding empty terms */ + status = _notmuch_message_add_term (message, "body", ""); + printf("%d\n%d\n", message != NULL, status != NOTMUCH_STATUS_SUCCESS ); + } +EOF +cat < EXPECTED +== stdout == +1 +1 +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + test_begin_subtest "Handle removing all tags with closed db" cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} { -- 2.35.2