summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2024-04-02 19:30:40 +0200
committercgzones <cgzones@googlemail.com>2024-04-05 19:17:12 +0200
commit5846b7df4e891e3db85e2719d5d28507e0da2468 (patch)
treedd6a5750fd2c9698435d0adbbfeeb5c820117ddc
parent6eed4898468c0fae5a6e2d0ab0bb6954723a356f (diff)
Check for absolute paths in environment variables
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.
-rw-r--r--Settings.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Settings.c b/Settings.c
index 6cbe46b9..670acabe 100644
--- a/Settings.c
+++ b/Settings.c
@@ -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");

© 2014-2024 Faster IT GmbH | imprint | privacy policy