summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanu Kaskinen <tanu.kaskinen@linux.intel.com>2014-03-19 12:16:08 +0200
committerTanu Kaskinen <tanu.kaskinen@linux.intel.com>2014-03-28 14:54:58 +0200
commitaca30527e2f8241b52433a81f7e857b726d5093c (patch)
tree922b9e765c4a72a3ac55daaf6d538b6bb4400868
parente1440395d18310fe7648011737c579520c55d549 (diff)
util: Check that the home dir is an absolute path
Avoid unpredictable behaviour in case e.g. the HOME environment variable is incorrectly set up for whatever reason. I haven't seen non-absolute HOME anywhere, but this feels like a good sanity check anyway.
-rw-r--r--src/pulse/util.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/pulse/util.c b/src/pulse/util.c
index 6656bc3ff..50f90b85b 100644
--- a/src/pulse/util.c
+++ b/src/pulse/util.c
@@ -132,19 +132,23 @@ char *pa_get_host_name(char *s, size_t l) {
char *pa_get_home_dir(char *s, size_t l) {
char *e;
-#ifdef HAVE_PWD_H
char *dir;
+#ifdef HAVE_PWD_H
struct passwd *r;
#endif
pa_assert(s);
pa_assert(l > 0);
- if ((e = getenv("HOME")))
- return pa_strlcpy(s, e, l);
+ if ((e = getenv("HOME"))) {
+ dir = pa_strlcpy(s, e, l);
+ goto finish;
+ }
- if ((e = getenv("USERPROFILE")))
- return pa_strlcpy(s, e, l);
+ if ((e = getenv("USERPROFILE"))) {
+ dir = pa_strlcpy(s, e, l);
+ goto finish;
+ }
#ifdef HAVE_PWD_H
errno = 0;
@@ -158,13 +162,21 @@ char *pa_get_home_dir(char *s, size_t l) {
dir = pa_strlcpy(s, r->pw_dir, l);
pa_getpwuid_free(r);
+#endif /* HAVE_PWD_H */
- return dir;
-#else /* HAVE_PWD_H */
+finish:
+ if (!dir) {
+ errno = ENOENT;
+ return NULL;
+ }
- errno = ENOENT;
- return NULL;
-#endif
+ if (!pa_is_path_absolute(dir)) {
+ pa_log("Failed to get the home directory, not an absolute path: %s", dir);
+ errno = ENOENT;
+ return NULL;
+ }
+
+ return dir;
}
char *pa_get_binary_name(char *s, size_t l) {