From a830359f7afc8e98a2266ea023061efd6ad081a5 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 2 Jun 2016 17:37:26 +0200 Subject: [PATCH] Abort if neither --database-dir nor --base-dir is given. 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/adu.c b/adu.c index 37a0867..fe0caa5 100644 --- 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. -- 2.39.2