e sys man - double check root homedir to be paranoid

This commit is contained in:
Carsten Haitzler 2020-04-22 13:15:08 +01:00
parent ac37da4167
commit 2e75a9410e
1 changed files with 11 additions and 1 deletions

View File

@ -94,7 +94,7 @@ static void
setuid_setup(void)
{
struct passwd *pwent;
static char buf[4096];
static char buf[PATH_MAX];
uid = getuid();
gid = getgid();
@ -126,6 +126,16 @@ setuid_setup(void)
fprintf(stderr, "Root homedir too long\n");
exit(1);
}
if (pwent->pw_dir[0] != '/')
{
fprintf(stderr, "Root homedir %s is not a full path\n", pwent->pw_dir);
exit(1);
}
if (!realpath(pwent->pw_dir, buf))
{
fprintf(stderr, "Root homedir %s does not resolve\n", pwent->pw_dir);
exit(1);
}
snprintf(buf, sizeof(buf), "HOME=%s", pwent->pw_dir);
if (putenv(buf) == -1)
{