Skip to content

Commit

Permalink
Ensure HISTCONTROL prevents space-leading commands from adding to his…
Browse files Browse the repository at this point in the history
…tory (touch #1110)
  • Loading branch information
elfmz committed Oct 20, 2021
1 parent 3d3976a commit 61f9124
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions far2l/vtshell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,19 @@ class VTShell : VTOutputReader::IProcessor, VTInputReader::IProcessor, IVTShell
}
}

// Will need to ensure that HISTCONTROL prevents adding to history commands that start by space
// to avoid shell history pollution by far2l's intermediate script execution commands
std::string hc_override;
const char *hc = getenv("HISTCONTROL");
if (!hc || (!strstr(hc, "ignorespace") && !strstr(hc, "ignoreboth"))) {
hc_override = "ignorespace";
if (hc && *hc) {
hc_override+= ':';
hc_override+= hc;
}
fprintf(stderr, "Override HISTCONTROL='%s'\n", hc_override.c_str());
}

//shell = "/usr/bin/zsh";
//shell = "/bin/bash";
//shell = "/bin/sh";
Expand All @@ -395,6 +408,10 @@ class VTShell : VTOutputReader::IProcessor, VTInputReader::IProcessor, IVTShell
return r;
}

if (!hc_override.empty()) {
setenv("HISTCONTROL", hc_override.c_str(), 1);
}

// avoid locking current directory
if (chdir(home.c_str()) != 0) {
if (chdir("/") != 0) {
Expand Down

0 comments on commit 61f9124

Please sign in to comment.