Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / b9 / 302fe96532690852855133ac71247d50a5e2cf
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 arlo.cworth.org (Postfix) with ESMTP id AA4AD6DE0B2F\r
6  for <notmuch@notmuchmail.org>; Wed, 10 Jun 2015 00:19:24 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.206\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.206 tagged_above=-999 required=5 tests=[AWL=0.196, \r
12  T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id I7JtQgadaOSg for <notmuch@notmuchmail.org>;\r
16  Wed, 10 Jun 2015 00:19:23 -0700 (PDT)\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
18  [87.98.215.224])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id E00076DE02CB\r
20  for <notmuch@notmuchmail.org>; Wed, 10 Jun 2015 00:19:22 -0700 (PDT)\r
21 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
22  4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
23  id 1Z2aGe-0007UE-Ro; Wed, 10 Jun 2015 07:17:44 +0000\r
24 Received: (nullmailer pid 5329 invoked by uid 1000); Wed, 10 Jun 2015\r
25  07:17:09 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: David Bremner <david@tethera.net>, Morgan Veyret\r
28  <morgan.veyret@gmail.com>, notmuch@notmuchmail.org\r
29 Subject: [PATCH 2/2] lib: reject relative paths in n_d_{create,open}_verbose\r
30 Date: Wed, 10 Jun 2015 09:17:01 +0200\r
31 Message-Id: <1433920621-5279-2-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 2.1.4\r
33 In-Reply-To: <1433920621-5279-1-git-send-email-david@tethera.net>\r
34 References: <87oakqj5rm.fsf@maritornes.cs.unb.ca>\r
35  <1433920621-5279-1-git-send-email-david@tethera.net>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.18\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40  <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Wed, 10 Jun 2015 07:19:24 -0000\r
49 \r
50 There are many places in the notmuch code where the path is assumed to be absolute. If someone (TM) wants a project, one could remove these assumptions. In the mean time, prevent users from shooting themselves in the foot.\r
51 \r
52 Update test suite mark tests for this error as no longer broken, and\r
53 also convert some tests that used relative paths for nonexistent\r
54 directories.\r
55 ---\r
56  NEWS                       |  9 +++++++++\r
57  lib/database.cc            | 12 ++++++++++++\r
58  test/T360-symbol-hiding.sh | 21 +++++++++++----------\r
59  test/T560-lib-error.sh     | 10 ++++------\r
60  test/symbol-test.cc        |  6 +++---\r
61  5 files changed, 39 insertions(+), 19 deletions(-)\r
62 \r
63 diff --git a/NEWS b/NEWS\r
64 index 03254d5..004b867 100644\r
65 --- a/NEWS\r
66 +++ b/NEWS\r
67 @@ -1,3 +1,12 @@\r
68 +Notmuch 0.21 (UNRELEASED)\r
69 +=========================\r
70 +\r
71 +Library\r
72 +-------\r
73 +\r
74 +The use of absolute paths is now enforced when calling notmuch_database_{open, create}\r
75 +\r
76 +\r
77  Notmuch 0.20.1 (2015-06-01)\r
78  ===========================\r
79  \r
80 diff --git a/lib/database.cc b/lib/database.cc\r
81 index e726f62..6a15174 100644\r
82 --- a/lib/database.cc\r
83 +++ b/lib/database.cc\r
84 @@ -659,6 +659,12 @@ notmuch_database_create_verbose (const char *path,\r
85         goto DONE;\r
86      }\r
87  \r
88 +    if (path[0] != '/') {\r
89 +       message = strdup ("Error: Database path must be absolute.\n");\r
90 +       status = NOTMUCH_STATUS_PATH_ERROR;\r
91 +       goto DONE;\r
92 +    }\r
93 +\r
94      err = stat (path, &st);\r
95      if (err) {\r
96         IGNORE_RESULT (asprintf (&message, "Error: Cannot create database at %s: %s.\n",\r
97 @@ -849,6 +855,12 @@ notmuch_database_open_verbose (const char *path,\r
98         goto DONE;\r
99      }\r
100  \r
101 +    if (path[0] != '/') {\r
102 +       message = strdup ("Error: Database path must be absolute.\n");\r
103 +       status = NOTMUCH_STATUS_PATH_ERROR;\r
104 +       goto DONE;\r
105 +    }\r
106 +\r
107      if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {\r
108         message = strdup ("Out of memory\n");\r
109         status = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
110 diff --git a/test/T360-symbol-hiding.sh b/test/T360-symbol-hiding.sh\r
111 index d2b5d1f..98e4d4d 100755\r
112 --- a/test/T360-symbol-hiding.sh\r
113 +++ b/test/T360-symbol-hiding.sh\r
114 @@ -11,16 +11,17 @@ test_description='exception symbol hiding'\r
115  \r
116  . ./test-lib.sh\r
117  \r
118 -run_test(){\r
119 -    result=$(LD_LIBRARY_PATH="$TEST_DIRECTORY/../lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" $TEST_DIRECTORY/symbol-test 2>&1)\r
120 -}\r
121 -\r
122 -output="A Xapian exception occurred opening database: Couldn't stat 'fakedb/.notmuch/xapian'\r
123 -caught No chert database found at path \`./nonexistent'"\r
124 -\r
125 -mkdir -p fakedb/.notmuch\r
126 -\r
127 -test_expect_success 'running test' run_test\r
128 +test_begin_subtest 'running test' run_test\r
129 +mkdir -p ${PWD}/fakedb/.notmuch\r
130 +( LD_LIBRARY_PATH="$TEST_DIRECTORY/../lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \\r
131 +                $TEST_DIRECTORY/symbol-test ${PWD}/fakedb ${PWD}/nonexistent \\r
132 +                2>&1 | sed "s,${PWD},CWD,g") > OUTPUT\r
133 +\r
134 +cat <<EOF > EXPECTED\r
135 +A Xapian exception occurred opening database: Couldn't stat 'CWD/fakedb/.notmuch/xapian'\r
136 +caught No chert database found at path \`CWD/nonexistent'\r
137 +EOF\r
138 +test_expect_equal_file EXPECTED OUTPUT\r
139  \r
140  test_begin_subtest 'checking output'\r
141  test_expect_equal "$result" "$output"\r
142 diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh\r
143 index 9f5f7ae..b1e77aa 100755\r
144 --- a/test/T560-lib-error.sh\r
145 +++ b/test/T560-lib-error.sh\r
146 @@ -36,7 +36,6 @@ EOF\r
147  test_expect_equal_file EXPECTED OUTPUT\r
148  \r
149  test_begin_subtest "Open relative path"\r
150 -test_subtest_known_broken\r
151  test_C <<'EOF'\r
152  #include <stdio.h>\r
153  #include <notmuch.h>\r
154 @@ -55,7 +54,6 @@ EOF\r
155  test_expect_equal_file EXPECTED OUTPUT\r
156  \r
157  test_begin_subtest "Create database in relative path"\r
158 -test_subtest_known_broken\r
159  test_C <<'EOF'\r
160  #include <stdio.h>\r
161  #include <notmuch.h>\r
162 @@ -108,21 +106,21 @@ Error: Cannot create a database for a NULL path.\r
163  EOF\r
164  test_expect_equal_file EXPECTED OUTPUT\r
165  \r
166 -test_begin_subtest "Create database in non-existant directory"\r
167 -test_C <<'EOF'\r
168 +test_begin_subtest "Create database in nonexistent directory"\r
169 +test_C ${PWD}/nonexistent/foo<<'EOF'\r
170  #include <stdio.h>\r
171  #include <notmuch.h>\r
172  int main (int argc, char** argv)\r
173  {\r
174      notmuch_database_t *db;\r
175      notmuch_status_t stat;\r
176 -    stat = notmuch_database_create ("./nonexistent/foo", &db);\r
177 +    stat = notmuch_database_create (argv[1], &db);\r
178  }\r
179  EOF\r
180  cat <<'EOF' >EXPECTED\r
181  == stdout ==\r
182  == stderr ==\r
183 -Error: Cannot create database at ./nonexistent/foo: No such file or directory.\r
184 +Error: Cannot create database at CWD/nonexistent/foo: No such file or directory.\r
185  EOF\r
186  test_expect_equal_file EXPECTED OUTPUT\r
187  \r
188 diff --git a/test/symbol-test.cc b/test/symbol-test.cc\r
189 index f17ddc8..fb77b41 100644\r
190 --- a/test/symbol-test.cc\r
191 +++ b/test/symbol-test.cc\r
192 @@ -4,18 +4,18 @@\r
193  #include <notmuch.h>\r
194  \r
195  \r
196 -int main() {\r
197 +int main(int argc, char** argv) {\r
198    notmuch_database_t *notmuch;\r
199    char *message = NULL;\r
200  \r
201 -  if (notmuch_database_open_verbose  ("fakedb", NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch, &message))\r
202 +  if (notmuch_database_open_verbose  (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch, &message))\r
203        if (message) {\r
204           fputs (message, stderr);\r
205           free (message);\r
206        }\r
207  \r
208    try {\r
209 -    (void) new Xapian::WritableDatabase("./nonexistent", Xapian::DB_OPEN);\r
210 +    (void) new Xapian::WritableDatabase(argv[2], Xapian::DB_OPEN);\r
211    } catch (const Xapian::Error &error) {\r
212      printf("caught %s\n", error.get_msg().c_str());\r
213      return 0;\r
214 -- \r
215 2.1.4\r
216 \r