Skip to content

Commit

Permalink
fix --private-cwd problem
Browse files Browse the repository at this point in the history
  • Loading branch information
netblue30 committed Dec 19, 2021
1 parent f43d120 commit d2e10f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/firejail/fs_home.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,20 @@ void fs_check_private_dir(void) {
void fs_check_private_cwd(const char *dir) {
EUID_ASSERT();
invalid_filename(dir, 0); // no globbing
if (strcmp(dir, ".") == 0 || *dir != '/')
goto errout;

// Expand the working directory
cfg.cwd = expand_macros(dir);

// realpath/is_dir not used because path may not exist outside of jail
if (strstr(cfg.cwd, "..")) {
fprintf(stderr, "Error: invalid private working directory\n");
exit(1);
}
if (strstr(cfg.cwd, ".."))
goto errout;

return;
errout:
fprintf(stderr, "Error: invalid private working directory\n");
exit(1);
}

//***********************************************************************************
Expand Down
5 changes: 5 additions & 0 deletions src/firejail/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,11 @@ int sandbox(void* sandbox_arg) {
EUID_USER();
int cwd = 0;
if (cfg.cwd) {
if (is_link(cfg.cwd)) {
fprintf(stderr, "Error: unable to enter private working directory: %s\n", cfg.cwd);
exit(1);
}

if (chdir(cfg.cwd) == 0)
cwd = 1;
else if (arg_private_cwd) {
Expand Down

0 comments on commit d2e10f8

Please sign in to comment.