From a8523db838f91565a23263a1d5d2e81d91815cb7 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 2 Oct 2026 13:20:42 +0000 Subject: [PATCH] Change to the new working directory even if getcwd fails, GitHub issue 5658. --- spawn.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spawn.c b/spawn.c index 22dbe041d..70ef27f82 100644 --- a/spawn.c +++ b/spawn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spawn.c,v 1.53 2026/09/21 12:43:36 nicm Exp $ */ +/* $OpenBSD: spawn.c,v 1.54 2026/10/02 13:20:42 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott @@ -467,14 +467,14 @@ spawn_pane(struct spawn_context *sc, char **cause) new_wp->flags &= ~PANE_EMPTY; /* Store current working directory and change to new one. */ - if (getcwd(path, sizeof path) != NULL) { - if (chdir(new_wp->cwd) == 0) - actual_cwd = new_wp->cwd; - else if (home != NULL && chdir(home) == 0) - actual_cwd = home; - else if (chdir("/") == 0) - actual_cwd = "/"; - } + if (getcwd(path, sizeof path) == NULL) + strlcpy(path, "/", sizeof path); + if (chdir(new_wp->cwd) == 0) + actual_cwd = new_wp->cwd; + else if (home != NULL && chdir(home) == 0) + actual_cwd = home; + else if (chdir("/") == 0) + actual_cwd = "/"; /* Fork the new process. */ new_wp->pid = fdforkpty(ptm_fd, &new_wp->fd, new_wp->tty, NULL, &ws);