From 54db1806877c3caddf3732ade59fa6482fccdc39 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sat, 29 Dec 2012 13:26:27 +1900 Subject: [PATCH] [PATCH v3 3/5] dump: Disallow \n in message IDs --- c5/4caa766eb6f20917d602b332461751a4788257 | 127 ++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 c5/4caa766eb6f20917d602b332461751a4788257 diff --git a/c5/4caa766eb6f20917d602b332461751a4788257 b/c5/4caa766eb6f20917d602b332461751a4788257 new file mode 100644 index 000000000..a78585d3d --- /dev/null +++ b/c5/4caa766eb6f20917d602b332461751a4788257 @@ -0,0 +1,127 @@ +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 6681F431FB6 + for ; Fri, 28 Dec 2012 10:26:50 -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 uarQRKSTpxh2 for ; + Fri, 28 Dec 2012 10:26:49 -0800 (PST) +Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU + [18.7.68.36]) + by olra.theworths.org (Postfix) with ESMTP id D4F28431FBC + for ; Fri, 28 Dec 2012 10:26:48 -0800 (PST) +X-AuditID: 12074424-b7f4e6d0000004ca-31-50dde467cb8f +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP + id AF.44.01226.764EDD05; Fri, 28 Dec 2012 13:26:48 -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 qBSIQkOq003220; + Fri, 28 Dec 2012 13:26:46 -0500 +Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net + [76.21.105.205]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBSIQf1A012714 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Fri, 28 Dec 2012 13:26:43 -0500 (EST) +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1Toedj-0000sU-VM; Fri, 28 Dec 2012 13:26:39 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v3 3/5] dump: Disallow \n in message IDs +Date: Fri, 28 Dec 2012 13:26:27 -0500 +Message-Id: <1356719189-2837-4-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1356719189-2837-1-git-send-email-amdragon@mit.edu> +References: <1356719189-2837-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFjrPIsWRmVeSWpSXmKPExsUixG6nopvx5G6AQZesxY3WbkaLpunOFqvn + 8lhcvzmT2YHFY+esu+wet+6/Zvd4tuoWs8eWQ++ZA1iiuGxSUnMyy1KL9O0SuDKuzO9nLVgu + WLHr+RXmBsZbvF2MnBwSAiYSP/tWMUHYYhIX7q1n62Lk4hAS2Mcosf/JDXYIZwOjxIllS1gh + nItMEpd3n4HKzGWUmPzqMQtIP5uAhsS2/csZQWwRAWmJnXdns4LYzAJ5Eg8fbWUHsYUFLCQe + XT8PZrMIqEqsn7AJrIZXwF7i1LL17BB3KEp0P5vABmJzCjhIvJpyDswWAqmZsZx1AiP/AkaG + VYyyKblVurmJmTnFqcm6xcmJeXmpRbrmermZJXqpKaWbGMHh5qKyg7H5kNIhRgEORiUe3hO3 + 7wYIsSaWFVfmHmKU5GBSEuVd/gAoxJeUn1KZkVicEV9UmpNafIhRgoNZSYS3rxkox5uSWFmV + WpQPk5LmYFES572ectNfSCA9sSQ1OzW1ILUIJivDwaEkwev+GKhRsCg1PbUiLTOnBCHNxMEJ + MpwHaHgESA1vcUFibnFmOkT+FKOilDhvJEhCACSRUZoH1wtLB68YxYFeEeZVA6niAaYSuO5X + QIOZgAZb89wBGVySiJCSamB0mmVs9DlGI1r97lSfn0l/HdLm3G6xu/Dp2Nddv9Sao1u4Nnpn + 7K3cFfPb8ejtHyfcuJa/VnhpvZ9rqbXm5qWp5RsZs1a6Pf39zHvGXwa+NRGCreeMGE0ePYj9 + ERSz8IEb47R2zbhNEp67pmTP9/4QeUGdZ19IScHazOrWf2X9gU1FAsFCxoVKLMUZiYZazEXF + iQBsWIfn4gIAAA== +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: Fri, 28 Dec 2012 18:26:50 -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 | 9 +++++++++ + test/random-corpus.c | 4 +++- + 2 files changed, 12 insertions(+), 1 deletion(-) + +diff --git a/notmuch-dump.c b/notmuch-dump.c +index d2dad40..29d79da 100644 +--- a/notmuch-dump.c ++++ b/notmuch-dump.c +@@ -132,6 +132,15 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[]) + if (output_format == DUMP_FORMAT_SUP) { + fputs (")\n", output); + } else { ++ if (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, "Error: cannot dump message id containing line break: %s\n", message_id); ++ return 1; ++ } + if (hex_encode (notmuch, message_id, + &buffer, &buffer_size) != HEX_SUCCESS) { + fprintf (stderr, "Error: failed to hex-encode msg-id %s\n", +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