diff --git a/ChangeLog b/ChangeLog
index ed0dabdfd78b3bfdf810264de5d44d60adafe089..924be711ae0fe06510a1c1c7cb216b19a3f267b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-01-22  Benno Schulenberg  <bensberg@justemail.net>
+	* 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  <bensberg@justemail.net>
 	* 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 71099f3fa4c2626bf0f35616d10a7c69c24c4006..6bd8b571456ad13fb9529227e5f71236e9c22b3d 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)