diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2026-03-30 00:42:00 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-04-02 02:41:56 +0000 |
| commit | 72252591ac01037fa53501adb88f00d5d3cc09ed (patch) | |
| tree | 4e77bbe6c3575b8988308e6e56875a4dfed68021 | |
| parent | ffbf3fecdeffa17c0745e7ed342989acb620d68e (diff) | |
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
| -rw-r--r-- | libexec/rtld-elf/tests/Makefile | 1 | ||||
| -rw-r--r-- | libexec/rtld-elf/tests/dlopen_hash_test.c | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/libexec/rtld-elf/tests/Makefile b/libexec/rtld-elf/tests/Makefile index 3c05b52b83bb..4fbc32d87615 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 000000000000..a95ebdb34381 --- /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 <iwtcex@gmail.com> + * Copyright 2026 The FreeBSD Foundation + * + * Portions of this software were developed by + * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from + * the FreeBSD Foundation. + */ + +#include <atf-c.h> +#include <dlfcn.h> +#include <fcntl.h> +#include <link.h> +#include <stdio.h> + +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(); +} |
