]> git.tuebingen.mpg.de Git - adu.git/commitdiff
Abort if neither --database-dir nor --base-dir is given.
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 2 Jun 2016 15:37:26 +0000 (17:37 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 24 Jun 2016 10:59:36 +0000 (12:59 +0200)
If --database-dir is not given, adu concatenates the database root
directory (which defaults to /var/lib/adu) with the value of the
--base-dir argument. However, if --base-dir is not given either,
base_dir_arg is NULL, and the concatenated string becomes the result
is /var/lib/adu(null), at least on glibc.

With this patch applied, adu handles this case more gracefully: it
prints an error message and aborts early.

adu.c

diff --git a/adu.c b/adu.c
index 37a086772fec78a8c099bbfb655e2cb5a734e0b2..fe0caa501a2ce35e5f83273af8dace42f420bde4 100644 (file)
--- a/adu.c
+++ b/adu.c
@@ -296,9 +296,15 @@ static void get_database_dir_or_die(void)
 
        if (conf.database_dir_given)
                tmp = adu_strdup(conf.database_dir_arg);
-       else
+       else {
+               if (!conf.base_dir_arg) {
+                       EMERG_LOG("fatal: neither database dir "
+                               "nor base dir given\n");
+                       exit(EXIT_FAILURE);
+               }
                tmp = make_message("%s%s",
                        conf.database_root_arg, conf.base_dir_arg);
+       }
        /*
         * As we change the cwd during database creation, database_dir
         * must be an absolute path.