[PATCH 1/1] cli: add some constraints to tags
authorJani Nikula <jani@nikula.org>
Thu, 10 Nov 2011 21:14:31 +0000 (23:14 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:03 +0000 (09:40 -0800)
2f/adb83588c151ba26ae0535f281b4cb3270b69d [new file with mode: 0644]

diff --git a/2f/adb83588c151ba26ae0535f281b4cb3270b69d b/2f/adb83588c151ba26ae0535f281b4cb3270b69d
new file mode 100644 (file)
index 0000000..1f3a249
--- /dev/null
@@ -0,0 +1,117 @@
+Return-Path: <jani@nikula.org>\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 A184C429E25\r
+       for <notmuch@notmuchmail.org>; Thu, 10 Nov 2011 13:14:38 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\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 c0h1OHPn5cil for <notmuch@notmuchmail.org>;\r
+       Thu, 10 Nov 2011 13:14:38 -0800 (PST)\r
+Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
+       [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id D6FCD431FB6\r
+       for <notmuch@notmuchmail.org>; Thu, 10 Nov 2011 13:14:37 -0800 (PST)\r
+Received: by faan15 with SMTP id n15so3758488faa.26\r
+       for <notmuch@notmuchmail.org>; Thu, 10 Nov 2011 13:14:36 -0800 (PST)\r
+Received: by 10.223.6.15 with SMTP id 15mr14472817fax.4.1320959676549;\r
+       Thu, 10 Nov 2011 13:14:36 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id g25sm12716529fae.16.2011.11.10.13.14.35\r
+       (version=SSLv3 cipher=OTHER); Thu, 10 Nov 2011 13:14:35 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/1] cli: add some constraints to tags\r
+Date: Thu, 10 Nov 2011 23:14:31 +0200\r
+Message-Id:\r
+ <3da260c7687fafe2cbc17bad129a8b1edb05c6d0.1320958534.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1320958534.git.jani@nikula.org>\r
+References: <cover.1320958534.git.jani@nikula.org>\r
+In-Reply-To: <cover.1320958534.git.jani@nikula.org>\r
+References: <cover.1320958534.git.jani@nikula.org>\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: Thu, 10 Nov 2011 21:14:38 -0000\r
+\r
+Forbid zero length tags, tags with leading '-', tags with leading or\r
+trailing whitespace, and tags containing whitespace other than space ' '.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ notmuch-client.h |    1 +\r
+ notmuch-tag.c    |   20 ++++++++++++++++++++\r
+ 2 files changed, 21 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index b50cb38..ff286b0 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -46,6 +46,7 @@\r
+ #include <dirent.h>\r
+ #include <errno.h>\r
+ #include <signal.h>\r
++#include <ctype.h>\r
\r
+ #include <talloc.h>\r
\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index dded39e..fb7a2f3 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -30,6 +30,22 @@ handle_sigint (unused (int sig))\r
+     interrupted = 1;\r
+ }\r
\r
++static int\r
++tag_valid(const char *tag)\r
++{\r
++    /* no zero length tag, leading whitespace or leading - */\r
++    if (*tag == '\0' || isspace ((unsigned char) *tag) || *tag == '-')\r
++      return 0;\r
++\r
++    /* no whitespace except ' ', no trailing whitespace */\r
++    for (tag++; *tag; tag++) {\r
++      if (isspace ((unsigned char) *tag) && (*tag != ' ' || *(tag+1) == '\0'))\r
++          return 0;\r
++    }\r
++\r
++    return 1;\r
++}\r
++\r
+ int\r
+ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ {\r
+@@ -73,6 +89,10 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+           break;\r
+       }\r
+       if (argv[i][0] == '+') {\r
++          if (!tag_valid (argv[i] + 1)) {\r
++              fprintf (stderr, "Error: Invalid tag %s\n", argv[i] + 1);\r
++              return 1;\r
++          }\r
+           add_tags[add_tags_count++] = i;\r
+       } else if (argv[i][0] == '-') {\r
+           remove_tags[remove_tags_count++] = i;\r
+-- \r
+1.7.5.4\r
+\r