From 5b0ebee290393394d18337f9d707f6b532d3f2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 13 Feb 2021 10:48:58 +0100 Subject: [PATCH] client: -D,--working-directory: check path exists and is a directory --- client.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client.c b/client.c index 125b4cfa..c012555c 100644 --- a/client.c +++ b/client.c @@ -10,6 +10,7 @@ #include #include +#include #define LOG_MODULE "foot-client" #define LOG_ENABLE_DBG 0 @@ -125,9 +126,15 @@ main(int argc, char *const *argv) login_shell = true; break; - case 'D': + case 'D': { + struct stat st; + if (stat(optarg, &st) < 0 || !(st.st_mode & S_IFDIR)) { + fprintf(stderr, "error: %s: not a directory\n", optarg); + return EXIT_FAILURE; + } custom_cwd = optarg; break; + } case 'w': if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {