From 889fe9457a9cee14f3a781ebd95e309ff717b29b Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 7 Jan 2013 15:22:40 +1900 Subject: [PATCH] [PATCH v5 4/6] dump: Disallow \n in message IDs --- bf/f76a79fbc2277a03872dac51d1e544719c26ee | 131 ++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 bf/f76a79fbc2277a03872dac51d1e544719c26ee diff --git a/bf/f76a79fbc2277a03872dac51d1e544719c26ee b/bf/f76a79fbc2277a03872dac51d1e544719c26ee new file mode 100644 index 000000000..b60b57c77 --- /dev/null +++ b/bf/f76a79fbc2277a03872dac51d1e544719c26ee @@ -0,0 +1,131 @@ +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 96349431FDC + for ; Sun, 6 Jan 2013 12:23:14 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[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 eWvGPSbW8JwR for ; + Sun, 6 Jan 2013 12:23:14 -0800 (PST) +Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU + [18.7.68.35]) + by olra.theworths.org (Postfix) with ESMTP id D0189431FBF + for ; Sun, 6 Jan 2013 12:23:13 -0800 (PST) +X-AuditID: 12074423-b7ef96d000000725-23-50e9dd31753a +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP + id 27.D1.01829.13DD9E05; Sun, 6 Jan 2013 15:23:13 -0500 (EST) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r06KNBfY002905; + Sun, 6 Jan 2013 15:23:11 -0500 +Received: from drake.dyndns.org (a069.catapulsion.net [70.36.81.69]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id r06KMvMj020351 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sun, 6 Jan 2013 15:23:09 -0500 (EST) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1Trwk7-0007YH-LX; Sun, 06 Jan 2013 15:22:51 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v5 4/6] dump: Disallow \n in message IDs +Date: Sun, 6 Jan 2013 15:22:40 -0500 +Message-Id: <1357503762-28759-5-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1357503762-28759-1-git-send-email-amdragon@mit.edu> +References: <1357503762-28759-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFrrFIsWRmVeSWpSXmKPExsUixG6nomt492WAweJPahY3WrsZLZqmO1us + nstjcf3mTGaLNyvnsTqweuycdZfd4/DXhSwet+6/Zvd4tuoWs8eWQ++ZA1ijuGxSUnMyy1KL + 9O0SuDKWbDvEUvBSsOLbtLnMDYzT+LoYOTkkBEwkFv85zwxhi0lcuLeerYuRi0NIYB+jxIwj + JxkhnPWMEvMvvYfK7GeSuNzczQThzGWU2HJzGwtIP5uAhsS2/csZQWwRAWmJnXdns4IUMQs0 + MUpc2zSXDSQhLGAhcebiGyYQm0VAVeL0s/1gDbwCDhLdH1vZIQ5RlOh+NgGonoODU8BR4uM8 + WZCwEFDJnR332Scw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka6aXm1mil5pSuokRHIQu + yjsY/xxUOsQowMGoxMN7YeeLACHWxLLiytxDjJIcTEqivLsvvgwQ4kvKT6nMSCzOiC8qzUkt + PsQowcGsJMK77xhQjjclsbIqtSgfJiXNwaIkznst5aa/kEB6YklqdmpqQWoRTFaGg0NJglfy + DlCjYFFqempFWmZOCUKaiYMTZDgP0PCXt0GGFxck5hZnpkPkTzEqSonzyoA0C4AkMkrz4Hph + SeIVozjQK8K8BiBVPMAEA9f9CmgwE9Dg1MfPQQaXJCKkpBoYs9cw+R4/ssvfZVJ0jur53KvK + Tzvaz+buKotd9PvUqtNf2hnPXws4oOWqVXt++sTlN3852+z9cih5Ve77iafPSJ63mz1J+IP6 + makxE5IXeN4+/Toz56LI8fp161aYfn6/zqdm52WNmjIGxWcXLvH3PuG91te+umzi3836V03X + KemLWqedi+B1XqzEUpyRaKjFXFScCACVouas7QIAAA== +Cc: tomi.ollila@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: Sun, 06 Jan 2013 20:23:14 -0000 + +When we switch to using regular Xapian queries in the dump format, \n +will cause problems, so we disallow it. Specially, while Xapian can +quote and parse queries containing \n without difficultly, quoted +queries containing \n still span multiple lines, which breaks the +line-orientedness of the dump format. Strictly speaking, we could +still round-trip these, but it would significantly complicate restore +as well as scripts that deal with tag dumps. This complexity would +come at absolutely no benefit: because of the RFC 2822 unfolding +rules, no amount of standards negligence can produce a message with a +message ID containing a line break (not even Outlook can do it!). + +Hence, we simply disallow it. +--- + notmuch-dump.c | 12 ++++++++++++ + test/random-corpus.c | 4 +++- + 2 files changed, 15 insertions(+), 1 deletion(-) + +diff --git a/notmuch-dump.c b/notmuch-dump.c +index d2dad40..5bbda36 100644 +--- a/notmuch-dump.c ++++ b/notmuch-dump.c +@@ -102,6 +102,18 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) + message = notmuch_messages_get (messages); + message_id = notmuch_message_get_message_id (message); + ++ if (output_format == DUMP_FORMAT_BATCH_TAG && ++ strchr (message_id, '\n')) { ++ /* This will produce a line break in the output, which ++ * would be difficult to handle in tools. However, it's ++ * also impossible to produce an email containing a line ++ * break in a message ID because of unfolding, so we can ++ * safely disallow it. */ ++ fprintf (stderr, "Warning: skipping message id containing line break: \"%s\"\n", message_id); ++ notmuch_message_destroy (message); ++ continue; ++ } ++ + if (output_format == DUMP_FORMAT_SUP) { + fprintf (output, "%s (", message_id); + } +diff --git a/test/random-corpus.c b/test/random-corpus.c +index f354d4b..8b7748e 100644 +--- a/test/random-corpus.c ++++ b/test/random-corpus.c +@@ -96,7 +96,9 @@ random_utf8_string (void *ctx, size_t char_count) + buf = talloc_realloc (ctx, buf, gchar, buf_size); + } + +- randomchar = random_unichar (); ++ do { ++ randomchar = random_unichar (); ++ } while (randomchar == '\n'); + + written = g_unichar_to_utf8 (randomchar, buf + offset); + +-- +1.7.10.4 + -- 2.26.2