Skip to content

Commit

Permalink
Check for absolute paths in environment variables
Browse files Browse the repository at this point in the history
Only use the environment variables HOME and XDG_CONFIG_HOME, or the home
directory from getpwuid(3) if they are absolute paths.
Avoid different behavior depending on the current working directory.
  • Loading branch information
cgzones committed Apr 5, 2024
1 parent 6eed489 commit 5846b7d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,14 +799,14 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, H
this->initialFilename = xStrdup(rcfile);
} else {
const char* home = getenv("HOME");
if (!home) {
if (!home || home[0] != '/') {
const struct passwd* pw = getpwuid(getuid());
home = pw ? pw->pw_dir : "";
home = (pw && pw->pw_dir && pw->pw_dir[0] == '/') ? pw->pw_dir : "";
}
const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
char* configDir = NULL;
char* htopDir = NULL;
if (xdgConfigHome) {
if (xdgConfigHome && xdgConfigHome[0] == '/') {
this->initialFilename = String_cat(xdgConfigHome, "/htop/htoprc");
configDir = xStrdup(xdgConfigHome);
htopDir = String_cat(xdgConfigHome, "/htop");
Expand Down

0 comments on commit 5846b7d

Please sign in to comment.