diff --git a/ChangeLog b/ChangeLog index ed0dabdf..924be711 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-01-22 Benno Schulenberg + * src/utils.c (get_homedir): Don't use $HOME when we're root, because + some sudos don't filter it out of the environment (which can lead to + a root-owned .nano/ directory in the invoking user's home directory). + It fixes https://bugs.launchpad.net/ubuntu/+source/nano/+bug/1471459. + 2016-01-21 Benno Schulenberg * src/prompt.c (get_prompt_string): Preserve the cursor position on the statusbar when just toggling a setting or making an excursion to diff --git a/src/utils.c b/src/utils.c index 71099f3f..6bd8b571 100644 --- a/src/utils.c +++ b/src/utils.c @@ -37,7 +37,9 @@ void get_homedir(void) if (homedir == NULL) { const char *homenv = getenv("HOME"); - if (homenv == NULL) { + /* When HOME isn't set, or when we're root, get the home directory + * from the password file instead. */ + if (homenv == NULL || geteuid() == 0) { const struct passwd *userage = getpwuid(geteuid()); if (userage != NULL)