[libimobiledevice] Don't make upowerd crash when run under systemd (#834359)

Bastien Nocera hadess at fedoraproject.org
Thu Sep 13 09:20:33 UTC 2012


commit d7730c8012e0da31a2b0699f8203aad930512b69
Author: Bastien Nocera <hadess at hadess.net>
Date:   Wed Sep 5 10:51:36 2012 +0100

    Don't make upowerd crash when run under systemd (#834359)

 0001-Don-t-crash-if-HOME-is-empty.patch |   60 +++++++++++++++++++++++++++++++
 libimobiledevice.spec                   |    8 ++++-
 2 files changed, 67 insertions(+), 1 deletions(-)
---
diff --git a/0001-Don-t-crash-if-HOME-is-empty.patch b/0001-Don-t-crash-if-HOME-is-empty.patch
new file mode 100644
index 0000000..eed0bae
--- /dev/null
+++ b/0001-Don-t-crash-if-HOME-is-empty.patch
@@ -0,0 +1,60 @@
+From 490c134a282c7091ee20918022bcf6a3607ec99a Mon Sep 17 00:00:00 2001
+From: Bastien Nocera <hadess at hadess.net>
+Date: Wed, 5 Sep 2012 10:07:15 +0100
+Subject: [PATCH] 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
+---
+ src/userpref.c | 23 ++++++++++++++++++++++-
+ 1 file changed, 22 insertions(+), 1 deletion(-)
+
+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 {
+-- 
+1.7.11.2
+
diff --git a/libimobiledevice.spec b/libimobiledevice.spec
index b43801e..107abbd 100644
--- a/libimobiledevice.spec
+++ b/libimobiledevice.spec
@@ -6,7 +6,7 @@
 
 Name:          libimobiledevice
 Version:       1.1.4
-Release:       3%{?dist}
+Release:       4%{?dist}
 Summary:       Library for connecting to mobile devices
 
 Group:         System Environment/Libraries
@@ -30,6 +30,8 @@ BuildRequires: swig
 Obsoletes: libimobiledevice-python <  %{version}-%{release} 
 %endif
 
+Patch0: 0001-Don-t-crash-if-HOME-is-empty.patch
+
 %description
 libimobiledevice is a library for connecting to mobile devices including phones 
 and music players
@@ -52,6 +54,7 @@ Python bindings for libimobiledevice.
 
 %prep
 %setup -q
+%patch0 -p1 -b .empty-home
 
 # Fix dir permissions on html docs
 chmod +x docs/html
@@ -95,6 +98,9 @@ find %{buildroot} -name '*.la' -exec rm -f {} ';'
 %endif
 
 %changelog
+* Wed Sep 05 2012 Bastien Nocera <bnocera at redhat.com> 1.1.4-4
+- Don't make upowerd crash when run under systemd (#834359)
+
 * Fri Aug 10 2012 Rex Dieter <rdieter at fedoraproject.org> - 1.1.4-3
 - disable broken python/cython bindings (for now, currently FTBFS)
 - track soname


More information about the scm-commits mailing list