Commit 823bdbae authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

safer code, check result of lstat

parent 1afbc190
...@@ -243,12 +243,14 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) { ...@@ -243,12 +243,14 @@ Settings* Settings_new(ProcessList* pl, Header* header, int cpuCount) {
htopDir = String_cat(home, "/.config/htop"); htopDir = String_cat(home, "/.config/htop");
} }
legacyDotfile = String_cat(home, "/.htoprc"); legacyDotfile = String_cat(home, "/.htoprc");
mkdir(configDir, 0700); (void) mkdir(configDir, 0700);
mkdir(htopDir, 0700); (void) mkdir(htopDir, 0700);
free(htopDir); free(htopDir);
free(configDir); free(configDir);
struct stat st; struct stat st;
lstat(legacyDotfile, &st); if (lstat(legacyDotfile, &st) != 0) {
st.st_mode = 0;
}
if (access(legacyDotfile, R_OK) != 0 || S_ISLNK(st.st_mode)) { if (access(legacyDotfile, R_OK) != 0 || S_ISLNK(st.st_mode)) {
free(legacyDotfile); free(legacyDotfile);
legacyDotfile = NULL; legacyDotfile = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment