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 QFLUObwmq2MMrAAAbAwnHQ (envelope-from ) for ; Tue, 27 Dec 2022 18:09:17 +0100 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 QEr/Obwmq2PzaQAAauVa8A (envelope-from ) for ; Tue, 27 Dec 2022 18:09:16 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (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 C5A8317834 for ; Tue, 27 Dec 2022 18:09:16 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 5E542604BE; Tue, 27 Dec 2022 17:09:01 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 1D0EB5FC23 for ; Tue, 27 Dec 2022 17:08:58 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 82B085FBA9; Tue, 27 Dec 2022 12:08:57 -0500 (EST) Received: (nullmailer pid 4007780 invoked by uid 1000); Tue, 27 Dec 2022 17:08:53 -0000 From: David Bremner To: Jose A Ortega Ruiz , David Bremner , notmuch@notmuchmail.org Subject: [PATCH v2 2/2] lib: add better diagnostics for over long filenames. Date: Tue, 27 Dec 2022 13:08:47 -0400 Message-Id: <20221227170847.4007402-3-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20221227170847.4007402-1-david@tethera.net> References: <87mtaej8nd.fsf@mail.jao.io> <20221227170847.4007402-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: FL5U5S272K5N5MAXD64F4GFEUCL73HPQ X-Message-ID-Hash: FL5U5S272K5N5MAXD64F4GFEUCL73HPQ 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-Country: DE X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1672160956; 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=7auXtIj76Bzr0QnRHCYkuxBUMtE670ZRSF2WqO3b7Yg=; b=BJy+xu0jc6rc/pJ4GXuUOKHBUX4U8c45NSfBLsBMwWgS4W/mNh8zC4Fub4u7Vq0W3cvvnl wUOVxvtPeb70Irp7rkXL0pWcwHtjzsb502b5Qt8gLu/SxZP8HVxwRv9pIvxZqVrCQMZM7C RpcTOa90Z/7EkVjqYDpdV8RI1Fedvx3a9PhM4ADf3Vu9Jz+r3WLkuvVOvQK3GxIP42Djqx yd1sQMiZiU7gVM3hRjpGF9PCyH1GC9+MXCuI5KJW1Tp/xe/70EOvbebwLMCzdYkFS04Gxg o5G8aPa8aJgMhKrn7GMynMP44wP6RHlcq2ZktsQPZtuXkEH5s/EPLUQq2gUBuQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1672160956; a=rsa-sha256; cv=none; b=c11+ZyOe4E2rYYzfXHPIoGVxS7a4mQjAnLjS7ImcHOfqlfmJIx6SDPWos7hgryi1IU6H91 h+u1bCI05ZijtAQvLCB+tG9EAe7m3gK0Baeoa8B8iYiGUSvGWvWhReA2u/LhCWjDfeBqQH uv88iadn+B4CAS6r8xJ8ePn4uXzMUuYmsXXb/81JA1825ZJ9ATV3farBnHbtchviL01OOh zBkRs56Q3SqaeWaCwUvOqe3Ft4fdwOzM3n4vt/mW0LUzVn+uu28Ximjbviz042YSqxS6W7 sqI0BRZxyoIyFlaOn/B3H7Eo1Bmrc5CW5OZHpSFwQHh8Fv78ee4cpVBrHAYWUw== X-Spam-Score: -0.40 X-Migadu-Queue-Id: C5A8317834 Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org; dmarc=none X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -0.40 X-TUID: dWtTuF4YtGX2 Previously we just crashed with an internal error. With this change, the caller can handle it better. Update notmuch-new so that it doesn't crash with "unknown error code" because of this change. --- lib/message.cc | 16 ++++++++++++---- lib/notmuch.h | 2 ++ notmuch-new.c | 4 ++++ test/T050-new.sh | 1 - 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 5ccca95a..1b1a071a 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -941,6 +941,7 @@ _notmuch_message_add_filename (notmuch_message_t *message, { const char *relative, *directory; notmuch_status_t status; + notmuch_private_status_t private_status; void *local = talloc_new (message); char *direntry; @@ -964,10 +965,17 @@ _notmuch_message_add_filename (notmuch_message_t *message, /* New file-direntry allows navigating to this message with * notmuch_directory_get_child_files() . */ - status = COERCE_STATUS (_notmuch_message_add_term (message, "file-direntry", direntry), - "adding file-direntry term"); - if (status) - return status; + private_status = _notmuch_message_add_term (message, "file-direntry", direntry); + switch (private_status) { + case NOTMUCH_PRIVATE_STATUS_SUCCESS: + break; + case NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG: + _notmuch_database_log (message->notmuch, "filename too long for file-direntry term: %s\n", + filename); + return NOTMUCH_STATUS_PATH_ERROR; + default: + return COERCE_STATUS (private_status, "adding file-direntry term"); + } status = _notmuch_message_add_folder_terms (message, directory); if (status) diff --git a/lib/notmuch.h b/lib/notmuch.h index 0b0540b1..ce375c04 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -293,6 +293,8 @@ typedef struct _notmuch_indexopts notmuch_indexopts_t; * * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory. * + * NOTMUCH_STATUS_PATH_ERROR: filename is too long + * * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to create the * database file (such as permission denied, or file not found, * etc.), or the database already exists. diff --git a/notmuch-new.c b/notmuch-new.c index 346e6469..4a53e3eb 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -413,6 +413,10 @@ add_file (notmuch_database_t *notmuch, const char *filename, case NOTMUCH_STATUS_FILE_NOT_EMAIL: fprintf (stderr, "Note: Ignoring non-mail file: %s\n", filename); break; + case NOTMUCH_STATUS_PATH_ERROR: + fprintf (stderr, "Note: Ignoring non-indexable path: %s\n", filename); + (void) print_status_database ("add_file", notmuch, status); + break; case NOTMUCH_STATUS_FILE_ERROR: /* Someone renamed/removed the file between scandir and now. */ state->vanished_files++; diff --git a/test/T050-new.sh b/test/T050-new.sh index f0a56c96..3167d338 100755 --- a/test/T050-new.sh +++ b/test/T050-new.sh @@ -384,7 +384,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "Long file names have reasonable diagnostics" -test_subtest_known_broken printf -v name 'f%.0s' {1..234} generate_message "[filename]=$name" notmuch new 2>&1 | notmuch_dir_sanitize >OUTPUT -- 2.35.2