mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
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.
This commit is contained in:
parent
e1440395d1
commit
aca30527e2
1 changed files with 22 additions and 10 deletions
|
|
@ -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 *pa_get_home_dir(char *s, size_t l) {
|
||||||
char *e;
|
char *e;
|
||||||
#ifdef HAVE_PWD_H
|
|
||||||
char *dir;
|
char *dir;
|
||||||
|
#ifdef HAVE_PWD_H
|
||||||
struct passwd *r;
|
struct passwd *r;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pa_assert(s);
|
pa_assert(s);
|
||||||
pa_assert(l > 0);
|
pa_assert(l > 0);
|
||||||
|
|
||||||
if ((e = getenv("HOME")))
|
if ((e = getenv("HOME"))) {
|
||||||
return pa_strlcpy(s, e, l);
|
dir = pa_strlcpy(s, e, l);
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
if ((e = getenv("USERPROFILE")))
|
if ((e = getenv("USERPROFILE"))) {
|
||||||
return pa_strlcpy(s, e, l);
|
dir = pa_strlcpy(s, e, l);
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_PWD_H
|
#ifdef HAVE_PWD_H
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
@ -158,13 +162,21 @@ char *pa_get_home_dir(char *s, size_t l) {
|
||||||
dir = pa_strlcpy(s, r->pw_dir, l);
|
dir = pa_strlcpy(s, r->pw_dir, l);
|
||||||
|
|
||||||
pa_getpwuid_free(r);
|
pa_getpwuid_free(r);
|
||||||
|
#endif /* HAVE_PWD_H */
|
||||||
|
|
||||||
|
finish:
|
||||||
|
if (!dir) {
|
||||||
|
errno = ENOENT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
return dir;
|
||||||
#else /* HAVE_PWD_H */
|
|
||||||
|
|
||||||
errno = ENOENT;
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pa_get_binary_name(char *s, size_t l) {
|
char *pa_get_binary_name(char *s, size_t l) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue