Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id CC151431FC9 for ; Mon, 18 Nov 2013 21:19:22 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.699 X-Spam-Level: X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zykYf31E3dd2 for ; Mon, 18 Nov 2013 21:19:15 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com [209.85.215.49]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 874CC431FC2 for ; Mon, 18 Nov 2013 21:19:15 -0800 (PST) Received: by mail-la0-f49.google.com with SMTP id er20so5564241lab.22 for ; Mon, 18 Nov 2013 21:19:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=fLfDEb0IGpEx/WJixURzhGCCKhddz8tMjKFxA3UzbJA=; b=xQtMR/kDL4gQ+YppHemzr4wScSZcqeJq/SEidRcjvxQ0dynDh94j9h2xSWd9/Qz4f5 KH/AYVu8LFzxQvw0tvdQs4FO9aGE05fALmFK29NaT/h3dHXndX9A6+7uNol9iTCC4UCG DgLxMigVG32Pj4GqFom3MfUiHUOmP+ZvIyanQyo7cUIEBuNKMAA3Tw+1jF2gg2yNGFd5 UIsh9gI78plS9NQ/XeVXT31EZbkCjeVhZXjxmVq0tS8eDry2C6T3n6CLvQKlkou/pgbz KuvRo570Rj5eBd8kenyzG3iqqjUrL2hGoLfOb5SgOjwdCogOu4rtD5jjXLJk3dw3DwQ+ Tqiw== X-Received: by 10.112.134.3 with SMTP id pg3mr16300431lbb.11.1384837880548; Mon, 18 Nov 2013 21:11:20 -0800 (PST) Received: from deskari.tieu.ti.com (a91-156-160-115.elisa-laajakaista.fi. [91.156.160.115]) by mx.google.com with ESMTPSA id m5sm11942484laj.4.2013.11.18.21.11.18 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Nov 2013 21:11:19 -0800 (PST) Sender: Tomi Valkeinen From: Tomi Valkeinen To: notmuch@notmuchmail.org Subject: [PATCH 2/2] lib: fix error handling Date: Tue, 19 Nov 2013 07:10:31 +0200 Message-Id: <1384837831-9206-2-git-send-email-tomi.valkeinen@iki.fi> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1384837831-9206-1-git-send-email-tomi.valkeinen@iki.fi> References: <1384837831-9206-1-git-send-email-tomi.valkeinen@iki.fi> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Nov 2013 05:19:22 -0000 Currently if a Xapian exception happens in notmuch_message_get_header, the exception is not caught leading to crash. In notmuch_message_get_date the exception is caught, but an internal error is raised, again leading to crash. This patch fixes the error handling by making both functions catch the Xapian exceptions, print an error and return NULL or 0. The 'notmuch->exception_reported' is also set, as is done elsewhere, even if I don't really get the idea of that field. Signed-off-by: Tomi Valkeinen --- lib/message.cc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 1b46379..c91f3a5 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -412,19 +412,27 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message) const char * notmuch_message_get_header (notmuch_message_t *message, const char *header) { - std::string value; + try { + std::string value; - /* Fetch header from the appropriate xapian value field if - * available */ - if (strcasecmp (header, "from") == 0) - value = message->doc.get_value (NOTMUCH_VALUE_FROM); - else if (strcasecmp (header, "subject") == 0) - value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT); - else if (strcasecmp (header, "message-id") == 0) - value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID); + /* Fetch header from the appropriate xapian value field if + * available */ + if (strcasecmp (header, "from") == 0) + value = message->doc.get_value (NOTMUCH_VALUE_FROM); + else if (strcasecmp (header, "subject") == 0) + value = message->doc.get_value (NOTMUCH_VALUE_SUBJECT); + else if (strcasecmp (header, "message-id") == 0) + value = message->doc.get_value (NOTMUCH_VALUE_MESSAGE_ID); - if (!value.empty()) - return talloc_strdup (message, value.c_str ()); + if (!value.empty()) + return talloc_strdup (message, value.c_str ()); + + } catch (Xapian::Error &error) { + fprintf (stderr, "A Xapian exception occurred when reading header: %s\n", + error.get_msg().c_str()); + message->notmuch->exception_reported = TRUE; + return NULL; + } /* Otherwise fall back to parsing the file */ _notmuch_message_ensure_message_file (message); @@ -766,7 +774,9 @@ notmuch_message_get_date (notmuch_message_t *message) try { value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP); } catch (Xapian::Error &error) { - INTERNAL_ERROR ("Failed to read timestamp value from document."); + fprintf (stderr, "A Xapian exception occurred when reading date: %s\n", + error.get_msg().c_str()); + message->notmuch->exception_reported = TRUE; return 0; } -- 1.8.3.2