init: fix possible dereference of null pointer

This commit is contained in:
Matheus
2023-07-25 18:42:43 -03:00
parent cb235ae3cc
commit a1d9259ed9
+5
View File
@@ -8,6 +8,11 @@ int main() {
printf("init: Welcome to Astral!\n");
struct passwd* pw = getpwuid(getuid());
if (pw == NULL) {
perror("init: failed to open /etc/passwd");
return EXIT_FAILURE;
}
if (chdir(pw->pw_dir) == -1) {
perror("init: chdir to user home directory failed");
return EXIT_FAILURE;