Re: [PATCH v4 03/16] make shared crypto code behave library-like
[notmuch-archives.git] / 59 / f54e74f894065ee8bb795d934ba60829c637f5
1 Return-Path: <novalazy@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 3CE18431FDB\r
6         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:51:42 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id qXDT7WQbqaks for <notmuch@notmuchmail.org>;\r
17         Sat, 19 Jan 2013 16:51:41 -0800 (PST)\r
18 Received: from mail-da0-f49.google.com (mail-da0-f49.google.com\r
19         [209.85.210.49]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id A5217429E29\r
22         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:51:27 -0800 (PST)\r
23 Received: by mail-da0-f49.google.com with SMTP id v40so2153966dad.22\r
24         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:51:26 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
27         :references; bh=1yohSKjaez2Nd4GI903tIxQiuqcgfD7ugXonbEfpM8k=;\r
28         b=IqMEcDEbPCJGC7du67MFw3aEGBKKD+Ze2WaEmXDZ4DoISkQUKNCcFOMCf8gaDJromE\r
29         O45uIjVjYkX+9HKEkkLhstvZbMMuC6lLg5lWstEVnGNzBFYcNfND/Zvcx8rQm0wgCzTu\r
30         7wI5rSC/Y60Wp7/LfQRlyNaSzTImg1Zlwj5uT2mH9Ol2QDVoBbEoaGlEGLcQixAtVB/Y\r
31         Kfe1JleeL+/EXNZ4ZVdb6a2OKxibmgYvwWVH01u4Qe9sb+8FKQMzflQhssoHV1kYU6/l\r
32         QRC0/4xzH5PLfM/HQnmAy9DD12CdZSc4TzHQymhO3AUu3o5pY49K5rtTG+kLkcb/u7ws\r
33         YsMA==\r
34 X-Received: by 10.68.231.10 with SMTP id tc10mr18398405pbc.81.1358643086760;\r
35         Sat, 19 Jan 2013 16:51:26 -0800 (PST)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215])\r
38         by mx.google.com with ESMTPS id ti9sm5807538pbc.16.2013.01.19.16.51.24\r
39         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
40         Sat, 19 Jan 2013 16:51:26 -0800 (PST)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v3 11/20] insert: prevent writes outside Maildir hierarchy\r
44 Date: Sun, 20 Jan 2013 11:49:55 +1100\r
45 Message-Id: <1358643004-14522-12-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.7.12.1\r
47 In-Reply-To: <1358643004-14522-1-git-send-email-novalazy@gmail.com>\r
48 References: <1358643004-14522-1-git-send-email-novalazy@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Sun, 20 Jan 2013 00:51:42 -0000\r
62 \r
63 Don't accept a --folder name that contains a ".." component,\r
64 in order to prevent writing outside of the Maildir hierarchy.\r
65 ---\r
66  notmuch-insert.c | 21 +++++++++++++++++++++\r
67  1 file changed, 21 insertions(+)\r
68 \r
69 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
70 index ba8cf5a..67ef94a 100644\r
71 --- a/notmuch-insert.c\r
72 +++ b/notmuch-insert.c\r
73 @@ -39,6 +39,23 @@ safe_gethostname (char *hostname, size_t len)\r
74      return (strchr (hostname, '/') == NULL);\r
75  }\r
76  \r
77 +/* Check the specified folder name does not contain a directory\r
78 + * component ".." to prevent writes outside of the Maildir hierarchy. */\r
79 +static notmuch_bool_t\r
80 +check_folder_name (const char *folder)\r
81 +{\r
82 +    const char *p = folder;\r
83 +\r
84 +    for (;;) {\r
85 +       if ((p[0] == '.') && (p[1] == '.') && (p[2] == '\0' || p[2] == '/'))\r
86 +           return FALSE;\r
87 +       p = strchr (p, '/');\r
88 +       if (!p)\r
89 +           return TRUE;\r
90 +       p++;\r
91 +    }\r
92 +}\r
93 +\r
94  /* Open a unique file in the Maildir 'tmp' directory.\r
95   * Returns the file descriptor on success, or -1 on failure.\r
96   * On success, file paths for the message in the 'tmp' and 'new'\r
97 @@ -282,6 +299,10 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
98      }\r
99  \r
100      if (folder != NULL) {\r
101 +       if (! check_folder_name (folder)) {\r
102 +           fprintf (stderr, "Error: bad folder name: %s\n", folder);\r
103 +           return 1;\r
104 +       }\r
105         maildir = talloc_asprintf (ctx, "%s/%s", db_path, folder);\r
106      } else {\r
107         maildir = talloc_asprintf (ctx, "%s", db_path);\r
108 -- \r
109 1.7.12.1\r
110 \r