From b4af69aa4d47bdeba233833a9d4084eb85c6fc30 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 2 Oct 2018 19:19:38 +0200 Subject: [PATCH] builtin/cd: fix segfault when PWD is not set --- builtin/cd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builtin/cd.c b/builtin/cd.c index 2e60b5f..522f316 100644 --- a/builtin/cd.c +++ b/builtin/cd.c @@ -55,6 +55,10 @@ int builtin_cd(struct mrsh_state *state, int argc, char *argv[]) { // This case is special as we print `pwd` at the end const char *oldpwd = mrsh_env_get(state, "OLDPWD", NULL); const char *pwd = mrsh_env_get(state, "PWD", NULL); + if (!pwd) { + fprintf(stderr, "cd: PWD is not set\n"); + return EXIT_FAILURE; + } if (!oldpwd) { fprintf(stderr, "cd: OLDPWD is not set\n"); return EXIT_FAILURE; -- 2.34.2