From 72252591ac01037fa53501adb88f00d5d3cc09ed Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 30 Mar 2026 03:42:00 +0300 Subject: [PATCH] rtld: add test for dlopen("#dirfd/path") Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D56152 --- libexec/rtld-elf/tests/Makefile | 1 + libexec/rtld-elf/tests/dlopen_hash_test.c | 45 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 libexec/rtld-elf/tests/dlopen_hash_test.c diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile index 3c05b52b83b..4fbc32d8761 100644 --- a/libexec/rtld-elf/tests/Makefile +++ b/libexec/rtld-elf/tests/Makefile @@ -14,6 +14,7 @@ SRCS.$t= $t.c common.c .endfor ATF_TESTS_C+= dlopen_test +ATF_TESTS_C+= dlopen_hash_test WARNS?= 3 diff --git a/libexec/rtld-elf/tests/dlopen_hash_test.c b/libexec/rtld-elf/tests/dlopen_hash_test.c new file mode 100644 index 00000000000..a95ebdb3438 --- /dev/null +++ b/libexec/rtld-elf/tests/dlopen_hash_test.c @@ -0,0 +1,45 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2026 Alex S + * Copyright 2026 The FreeBSD Foundation + * + * Portions of this software were developed by + * Konstantin Belousov under sponsorship from + * the FreeBSD Foundation. + */ + +#include +#include +#include +#include +#include + +ATF_TC_WITHOUT_HEAD(dlopen_hash); +ATF_TC_BODY(dlopen_hash, tc) +{ + void *handle; + char *pathfds; + char *name; + int testdir; + + handle = dlopen("libpythagoras.so.0", RTLD_LAZY); + ATF_REQUIRE(handle == NULL); + + testdir = open(atf_tc_get_config_var(tc, "srcdir"), + O_RDONLY | O_DIRECTORY); + ATF_REQUIRE(testdir >= 0); + + ATF_REQUIRE(asprintf(&pathfds, "%d", testdir) > 0); + ATF_REQUIRE(rtld_set_var("LIBRARY_PATH_FDS", pathfds) == 0); + + ATF_REQUIRE(asprintf(&name, "#%d/libpythagoras.so.0", testdir) > 0); + handle = dlopen(name, RTLD_LAZY); + ATF_REQUIRE(handle != NULL); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, dlopen_hash); + return atf_no_error(); +}