From d575f88bbe5bedfdb90cdef2d0aef7df63595ae1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 7 Mar 2019 10:53:23 +0100 Subject: [PATCH] user-util: be more strict when reading $HOME and $SHELL --- src/basic/user-util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/basic/user-util.c b/src/basic/user-util.c index 4cf4c5a3414..47d6763f1c9 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -458,7 +458,7 @@ int get_home_dir(char **_h) { /* Take the user specified one */ e = secure_getenv("HOME"); - if (e && path_is_absolute(e)) { + if (e && path_is_valid(e) && path_is_absolute(e)) { h = strdup(e); if (!h) return -ENOMEM; @@ -493,7 +493,8 @@ int get_home_dir(char **_h) { if (!p) return errno > 0 ? -errno : -ESRCH; - if (!path_is_absolute(p->pw_dir)) + if (!path_is_valid(p->pw_dir) || + !path_is_absolute(p->pw_dir)) return -EINVAL; h = strdup(p->pw_dir); @@ -514,7 +515,7 @@ int get_shell(char **_s) { /* Take the user specified one */ e = getenv("SHELL"); - if (e) { + if (e && path_is_valid(e) && path_is_absolute(e)) { s = strdup(e); if (!s) return -ENOMEM; @@ -549,7 +550,8 @@ int get_shell(char **_s) { if (!p) return errno > 0 ? -errno : -ESRCH; - if (!path_is_absolute(p->pw_shell)) + if (!path_is_valid(p->pw_shell) || + !path_is_absolute(p->pw_shell)) return -EINVAL; s = strdup(p->pw_shell); -- 2.47.3