From: Marek VavruĊĦa Date: Wed, 30 Sep 2015 17:01:28 +0000 (+0200) Subject: daemon: check that keyfile is readable and use abspath X-Git-Tag: v1.0.0-beta1~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc3e363d30cb9b038808edd2fcde3b34cd3a9d6d;p=thirdparty%2Fknot-resolver.git daemon: check that keyfile is readable and use abspath --- diff --git a/daemon/main.c b/daemon/main.c index bbebdab0b..cd233b88b 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -197,7 +197,8 @@ int main(int argc, char **argv) int forks = 1; array_t(char*) addr_set; array_init(addr_set); - const char *keyfile = NULL; + char *keyfile = NULL; + static char keyfile_buf[PATH_MAX + 1]; /* Long options. */ int c = 0, li = 0, ret = 0; @@ -225,9 +226,9 @@ int main(int argc, char **argv) } break; case 'k': - keyfile = optarg; - if (access(optarg, R_OK) != 0) { - log_error("[system] keyfile '%s': not readable\n", optarg); + keyfile = realpath(optarg, keyfile_buf); + if (!keyfile || access(optarg, R_OK|W_OK) != 0) { + log_error("[system] keyfile '%s': not readable/writeable\n", optarg); return EXIT_FAILURE; } break;