user-util: be more strict when reading $HOME and $SHELL

This commit is contained in:
Lennart Poettering
2019-03-07 10:53:23 +01:00
parent 47436d30bb
commit d575f88bbe

View File

@@ -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);