Skip to content

Commit

Permalink
Merge pull request #3674 from topimiettinen/rmenv-apply-early
Browse files Browse the repository at this point in the history
Apply --rmenv immediately to help to avoid the env var length check
  • Loading branch information
netblue30 committed Oct 17, 2020
2 parents 34c041e + aabd38f commit 2f0791e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/firejail/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,17 +1004,21 @@ int main(int argc, char **argv, char **envp) {
fprintf(stderr, "Error: too long arguments\n");
exit(1);
}
// Also remove requested environment variables
// entirely to avoid tripping the length check below
if (strncmp(argv[i], "--rmenv=", 8) == 0)
unsetenv(argv[i] + 8);
}

// sanity check for environment variables
for (i = 0, ptr = envp; ptr && *ptr && i < MAX_ENVS; i++, ptr++) {
if (strlen(*ptr) >= MAX_ENV_LEN) {
fprintf(stderr, "Error: too long environment variables\n");
fprintf(stderr, "Error: too long environment variables, please use --rmenv\n");
exit(1);
}
}
if (i >= MAX_ENVS) {
fprintf(stderr, "Error: too many environment variables\n");
fprintf(stderr, "Error: too many environment variables, please use --rmenv\n");
exit(1);
}

Expand Down
1 change: 1 addition & 0 deletions src/firejail/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
return 0;
}
if (strncmp(ptr, "rmenv ", 6) == 0) {
unsetenv(ptr + 6); // Remove also immediately from Firejail itself
env_store(ptr + 6, RMENV);
return 0;
}
Expand Down

0 comments on commit 2f0791e

Please sign in to comment.