~emersion/mrsh

b4af69aa4d47bdeba233833a9d4084eb85c6fc30 — emersion 3 years ago 7073943
builtin/cd: fix segfault when PWD is not set
1 files changed, 4 insertions(+), 0 deletions(-)

M builtin/cd.c
M builtin/cd.c => builtin/cd.c +4 -0
@@ 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;