Unbreak torture_config_make_absolute() on OpenBSD
The torture_config_make_absolute() and its _no_sshdir() version both segfault on OpenBSD. The reason for this is that the storage returned by getpwuid() is backed by mmap and is unapped by the getpwnam() call in ssh_path_expand_tilde(), so a later access to home segfaults. The possibility of this happening (getpwnam() overwriting values returned by getpwuid()) is explicitly called out in POSIX.
A simple fix is to work with copies of username and homedir.
Checklist
-
Commits have Signed-off-by:with name/author being identical to the commit author -
Code modified for feature -
Test suite updated with functionality tests -
Test suite updated with negative tests -
Documentation updated
Reviewer's checklist:
-
Any issues marked for closing are addressed -
There is a test suite reasonably covering new functionality or modifications -
Function naming, parameters, return values, types, etc., are consistent and according to CONTRIBUTING.md -
This feature/change has adequate documentation added -
No obvious mistakes in the code
Summary by Sourcery
Prevent segfaults in torture_config_make_absolute unit tests on OpenBSD by copying passwd data instead of referencing potentially unmapped memory
Bug Fixes:
- Fix torture_config_make_absolute tests to avoid use-after-unmap of getpwuid data on OpenBSD by duplicating pw_name and pw_dir before use
Tests:
- Add strdup calls and corresponding frees for user and home variables in torture_config_make_absolute tests to ensure valid memory handling
Edited by sourcery-ai