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