e sys main - double check return from getpwent homedir

This commit is contained in:
Carsten Haitzler 2020-04-22 12:37:51 +01:00
parent d42605f5c0
commit 5fb2fccd70
1 changed files with 11 additions and 1 deletions

View File

@ -116,13 +116,23 @@ setuid_setup(void)
fprintf(stderr, "Unable to obtain passwd entry\n");
exit(1);
}
if (!pwent->pw_dir)
{
fprintf(stderr, "No home dir for root\n");
exit(1);
}
if (strlen(pwent->pw_dir) > (sizeof(buf) - 8))
{
fprintf(stderr, "Root homedir too long\n");
exit(1);
}
snprintf(buf, sizeof(buf), "HOME=%s", pwent->pw_dir);
if (putenv(buf) == -1)
{
fprintf(stderr, "Unable to set $HOME environment\n");
exit(1);
}
// change CWD to / to avoid path search dlopens finding libs in ./
chdir("/");