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 D2514431FD2 for ; Wed, 25 Jul 2012 06:43:59 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 0KZogcThshG7 for ; Wed, 25 Jul 2012 06:43:59 -0700 (PDT) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 1842E431FC2 for ; Wed, 25 Jul 2012 06:43:57 -0700 (PDT) Received: by mail-pb0-f53.google.com with SMTP id rr13so1767731pbb.26 for ; Wed, 25 Jul 2012 06:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=HCNQ5SLkR8io4tFdlaCGFaOkej/t5dZz19fDDEzzmWk=; b=VRSv5ySDKUCu67MqZa2NGGmKLbDf+g2yhsIw1XBofGiPM+uNIJLWUaQpumwY4mULt7 mjAvvuBVTgHBYaUkMb276H99O2Y6YMhSodVpXi8FzVqAFlLuzowJ8CEs1Zaep27I2xHQ c4fNJ0kxXtKo76+bJH1qNjGJ8co271WvEFS7u/Pu47INXLPTBDbPGxj2IRwgHtSqFI/U bxJqP+yIWdclvB2jxp9Wv1y9/9YaJeTeAx9UPPxYqNWuBhEptCZedZfXYhI7xZFUm7IR cqafR0qyI+MdV/ooIqPEMXHNEqs6kwbWwVM2FgV+h019myFul611fv5wNFexTABULXlv c9cQ== Received: by 10.68.241.35 with SMTP id wf3mr47176468pbc.102.1343223836875; Wed, 25 Jul 2012 06:43:56 -0700 (PDT) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id og4sm14410647pbb.48.2012.07.25.06.43.54 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jul 2012 06:43:56 -0700 (PDT) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH 08/18] insert: check folder name Date: Wed, 25 Jul 2012 23:42:37 +1000 Message-Id: <1343223767-9812-8-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1343223767-9812-1-git-send-email-novalazy@gmail.com> References: <1343223767-9812-1-git-send-email-novalazy@gmail.com> 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: Wed, 25 Jul 2012 13:44:00 -0000 Don't accept folder names containing a ".." component, to prevent writing outside of the maildir. --- notmuch-insert.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index 6398618..ee51a87 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -25,6 +25,22 @@ #include static notmuch_bool_t +check_folder_name (const char *folder) +{ + const char *p = folder; + + /* Check ".." appears nowhere in the folder name. */ + for (;;) { + if ((p[0] == '.') && (p[1] == '.') && (p[2] == '\0' || p[2] == '/')) + return FALSE; + p = strchr (p, '/'); + if (!p) + return TRUE; + p++; + } +} + +static notmuch_bool_t safe_gethostname (char *hostname, size_t hostname_size) { if (gethostname (hostname, hostname_size) == -1) { @@ -232,6 +248,10 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) db_path = notmuch_config_get_database_path (config); if (folder != NULL) { + if (! check_folder_name (folder)) { + fprintf (stderr, "Error: bad folder name: %s\n", folder); + return 1; + } maildir = talloc_asprintf (ctx, "%s/%s", db_path, folder); } else { maildir = talloc_asprintf (ctx, "%s", db_path); -- 1.7.4.4