diff --git a/usr.sbin/jail/command.c b/usr.sbin/jail/command.c --- a/usr.sbin/jail/command.c +++ b/usr.sbin/jail/command.c @@ -788,7 +788,7 @@ setenv("HOME", pwd->pw_dir, 1); setenv("SHELL", *pwd->pw_shell ? pwd->pw_shell : _PATH_BSHELL, 1); - if (clean && chdir(pwd->pw_dir) < 0) { + if (clean && username && chdir(pwd->pw_dir) < 0) { jail_warnx(j, "chdir %s: %s", pwd->pw_dir, strerror(errno)); exit(1); diff --git a/usr.sbin/jexec/jexec.c b/usr.sbin/jexec/jexec.c --- a/usr.sbin/jexec/jexec.c +++ b/usr.sbin/jexec/jexec.c @@ -129,7 +129,7 @@ setenv("HOME", pwd->pw_dir, 1); setenv("SHELL", *pwd->pw_shell ? pwd->pw_shell : _PATH_BSHELL, 1); - if (clean && chdir(pwd->pw_dir) < 0) + if (clean && username && chdir(pwd->pw_dir) < 0) err(1, "chdir: %s", pwd->pw_dir); endpwent(); }