[PATCH 1/2] tag: Disallow adding malformed tags to messages
authorAustin Clements <amdragon@MIT.EDU>
Fri, 26 Oct 2012 20:54:12 +0000 (16:54 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:04 +0000 (09:50 -0800)
5c/e8e69e656a73e27e9a6f2ec9306a83464611d8 [new file with mode: 0644]

diff --git a/5c/e8e69e656a73e27e9a6f2ec9306a83464611d8 b/5c/e8e69e656a73e27e9a6f2ec9306a83464611d8
new file mode 100644 (file)
index 0000000..f628c50
--- /dev/null
@@ -0,0 +1,121 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E65C1431FAF\r
+       for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 13:54:21 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id fqWq7snfVdtz for <notmuch@notmuchmail.org>;\r
+       Fri, 26 Oct 2012 13:54:21 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
+       [18.7.68.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 60051431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 13:54:21 -0700 (PDT)\r
+X-AuditID: 12074422-b7f746d0000008cc-56-508af87cd561\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 93.CB.02252.C78FA805; Fri, 26 Oct 2012 16:54:20 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q9QKsJkW014430; \r
+       Fri, 26 Oct 2012 16:54:19 -0400\r
+Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q9QKsFNM019236\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Fri, 26 Oct 2012 16:54:18 -0400 (EDT)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TRqv1-0006Sm-4F; Fri, 26 Oct 2012 16:54:15 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] tag: Disallow adding malformed tags to messages\r
+Date: Fri, 26 Oct 2012 16:54:12 -0400\r
+Message-Id: <1351284853-24809-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFprJIsWRmVeSWpSXmKPExsUixCmqrVvzoyvAYOV1a4vrN2cyOzB6PFt1\r
+       izmAMYrLJiU1J7MstUjfLoEr4/PZtIJ3fBW/znQzNTDe4O5i5OSQEDCRWLvtBRuELSZx4d56\r
+       IJuLQ0hgH6PE9nnzGSGcDYwSh05PZQapEhI4xSRxcJ80RGIuo8T326dYQRJsAhoS2/YvZwSx\r
+       RQSkJXbenQ0U5+BgFlCT+NOlAhIWFnCRaJl8mQnEZhFQlXjSdxVsM6+Ag8T+WzfZIa6Ql3h6\r
+       v49tAiPvAkaGVYyyKblVurmJmTnFqcm6xcmJeXmpRbqmermZJXqpKaWbGEEhwO6itIPx50Gl\r
+       Q4wCHIxKPLw7nnQFCLEmlhVX5h5ilORgUhLlnfQdKMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmE\r
+       t+gYUI43JbGyKrUoHyYlzcGiJM57LeWmv5BAemJJanZqakFqEUxWhoNDSYJ3BshQwaLU9NSK\r
+       tMycEoQ0EwcnyHAeoOFgi3mLCxJzizPTIfKnGBWlxHk7QBICIImM0jy4XliMvmIUB3pFmLcX\r
+       pIoHGN9w3a+ABjMBDRZj7QQZXJKIkJJqYGRqfDz56KNpV47Ilibfqmmb2BWw9r1ndp2B7f60\r
+       VzlRRc4GyklCf37xNtdlC/ZInFb3SNsdJjXBOO/fGsYLb66G5m85H3yWW4ShxV95h9zUX5Pv\r
+       GvtFqYRZ35RPnbd634o3SqVuAbc8GwKCeD45F+4NXOoz/3CAysu+XfFTpNmv/FplcnzKfyWW\r
+       4oxEQy3mouJEANXW17ysAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 26 Oct 2012 20:54:22 -0000\r
+\r
+This disallows adding empty tags, since nothing but confusion follows\r
+in their wake, and disallows adding tags that begin with "-" because\r
+they are also confusing, the tag "-" is impossible to remove using the\r
+CLI, and because the syntax for removing such tags conflicts with long\r
+argument syntax.\r
+\r
+This does not place any restrictions on what tags can be removed, as\r
+that would make it difficult for people who have the misfortune of\r
+already having malformed tags to remove these tags.\r
+---\r
+ notmuch-tag.c |   11 +++++++++++\r
+ test/tagging  |    4 ++++\r
+ 2 files changed, 15 insertions(+)\r
+\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index 7d18639..d15f1ed 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -203,6 +203,17 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+           break;\r
+       }\r
+       if (argv[i][0] == '+' || argv[i][0] == '-') {\r
++          if (argv[i][0] == '+' && argv[i][1] == '\0') {\r
++              fprintf(stderr, "Error: tag names cannot be empty.\n");\r
++              return 1;\r
++          }\r
++          if (argv[i][0] == '+' && argv[i][1] == '-') {\r
++              /* This disallows adding the non-removable tag "-" and\r
++               * enables notmuch tag to take long options in the\r
++               * future. */\r
++              fprintf(stderr, "Error: tag names must not start with '-'.\n");\r
++              return 1;\r
++          }\r
+           tag_ops[tag_ops_count].tag = argv[i] + 1;\r
+           tag_ops[tag_ops_count].remove = (argv[i][0] == '-');\r
+           tag_ops_count++;\r
+diff --git a/test/tagging b/test/tagging\r
+index e4782ed..980ff92 100755\r
+--- a/test/tagging\r
++++ b/test/tagging\r
+@@ -46,4 +46,8 @@ test_expect_equal "$output" "\\r
+ thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; One (:\"  inbox tag1 unread)\r
+ thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag1 tag4 unread)"\r
+ \r
++test_expect_code 1 "Empty tag names" 'notmuch tag + One'\r
++\r
++test_expect_code 1 "Tag name beginning with -" 'notmuch tag +- One'\r
++\r
+ test_done\r
+-- \r
+1.7.10\r
+\r