Sophie

Sophie

distrib > Mageia > 3 > i586 > media > core-release-src > by-pkgid > f9e10992184eacc9d9a660c423146871 > files > 1

libimobiledevice-1.1.4-4.mga3.src.rpm

From 825da48d2e9c20086c4e34869da0b28376676b4c Mon Sep 17 00:00:00 2001
From: Bastien Nocera
Date: Wed, 05 Sep 2012 09:07:15 +0000
Subject: Don't crash if $HOME is empty

If both $XDG_CONFIG_HOME and $HOME are unset, we'd try to copy a NULL
string, causing a crash. This is the environment systemd provides to
its daemons, and that was causing upowerd to crash.

http://libiphone.lighthouseapp.com/projects/27916-libiphone/tickets/273-patch-fix-segfault-when-running-with-home-unset#ticket-273-2
http://libiphone.lighthouseapp.com/projects/27916/tickets/265-userpref_get_config_dir-segfaults-when-home-is-undefined
https://bugzilla.redhat.com/show_bug.cgi?id=834359
---
diff --git a/src/userpref.c b/src/userpref.c
index a0c3545..0e774b7 100644
--- a/src/userpref.c
+++ b/src/userpref.c
@@ -102,6 +102,20 @@ static char *userpref_utf16_to_utf8(wchar_t *unistr, long len, long *items_read,
 }
 #endif
 
+static const char *userpref_get_tmp_dir()
+{
+	const char *cdir = getenv("TMPDIR");
+	if (cdir && cdir[0])
+		return cdir;
+	cdir = getenv("TMP");
+	if (cdir && cdir[0])
+		return cdir;
+	cdir = getenv("TEMP");
+	if (cdir && cdir[0])
+		return cdir;
+	return "/tmp";
+}
+
 static const char *userpref_get_config_dir()
 {
 	if (__config_dir[0]) return __config_dir;
@@ -125,7 +139,14 @@ static const char *userpref_get_config_dir()
 	const char *cdir = getenv("XDG_CONFIG_HOME");
 	if (!cdir) {
 		cdir = getenv("HOME");
-		strcpy(__config_dir, cdir);
+		if (!cdir || !cdir[0]) {
+			const char *tdir = userpref_get_tmp_dir();
+			strcpy(__config_dir, tdir);
+			strcat(__config_dir, DIR_SEP_S);
+			strcat(__config_dir, "root");
+		} else {
+			strcpy(__config_dir, cdir);
+		}
 		strcat(__config_dir, DIR_SEP_S);
 		strcat(__config_dir, ".config");
 	} else {
--
cgit v0.9.0.2