There are scenarios (specifically when running in anonymous containers) where there is no entry in the password file for the current user, this causes getpwuid() to return a NULL pointer promptly causing a segfault.
This change detects this and then attempts to read the $HOME env var, and if that fails it falls back to the temp dir. Although the temp dir is not valid as a home dir, it is a valid path and so can be used by the calling function.
There are scenarios (specifically when running in anonymous containers) where there is no entry in the password file for the current user, this causes getpwuid() to return a NULL pointer promptly causing a segfault.
This change detects this and then attempts to read the $HOME env var, and if that fails it falls back to the temp dir. Although the temp dir is not valid as a home dir, it is a valid path and so can be used by the calling function.