aboutsummaryrefslogtreecommitdiff
path: root/lib/database.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2015-06-08 08:02:22 +0200
committerDavid Bremner <david@tethera.net>2015-06-12 07:34:50 +0200
commit32fd74b7aa9c24ec77f8c59d09f89e0535bf64cd (patch)
treeb457ce7f91011cbfafa70c908d682a7a3a87eaf3 /lib/database.cc
parentb59ad1a9cc6ea03764b1cd3d038920581ac5a9c4 (diff)
lib: reject relative paths in n_d_{create,open}_verbose
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. Update test suite mark tests for this error as no longer broken, and also convert some tests that used relative paths for nonexistent directories.
Diffstat (limited to 'lib/database.cc')
-rw-r--r--lib/database.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/database.cc b/lib/database.cc
index e726f629..6a151749 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -659,6 +659,12 @@ notmuch_database_create_verbose (const char *path,
goto DONE;
}
+ if (path[0] != '/') {
+ message = strdup ("Error: Database path must be absolute.\n");
+ status = NOTMUCH_STATUS_PATH_ERROR;
+ goto DONE;
+ }
+
err = stat (path, &st);
if (err) {
IGNORE_RESULT (asprintf (&message, "Error: Cannot create database at %s: %s.\n",
@@ -849,6 +855,12 @@ notmuch_database_open_verbose (const char *path,
goto DONE;
}
+ if (path[0] != '/') {
+ message = strdup ("Error: Database path must be absolute.\n");
+ status = NOTMUCH_STATUS_PATH_ERROR;
+ goto DONE;
+ }
+
if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {
message = strdup ("Out of memory\n");
status = NOTMUCH_STATUS_OUT_OF_MEMORY;