diff options
Diffstat (limited to 'regress/libexec/ld.so/randomdata/ld.so-cookie/test.c')
-rw-r--r-- | regress/libexec/ld.so/randomdata/ld.so-cookie/test.c | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/regress/libexec/ld.so/randomdata/ld.so-cookie/test.c b/regress/libexec/ld.so/randomdata/ld.so-cookie/test.c index 3053058913f..4d145096287 100644 --- a/regress/libexec/ld.so/randomdata/ld.so-cookie/test.c +++ b/regress/libexec/ld.so/randomdata/ld.so-cookie/test.c @@ -1,23 +1,53 @@ +#include <sys/types.h> +#include <sys/exec_elf.h> + #include <assert.h> #include <dlfcn.h> +#include <link.h> #include <stddef.h> +#include <string.h> -int -main() +static int +nonzero(char *s, size_t n) { - void *dso; - long *guardptr; - long guard; - extern long __guard[]; + size_t i; - dso = dlopen("ld.so", RTLD_LOCAL|RTLD_LAZY); - assert(dso != NULL); - guardptr = dlsym(dso, "__guard"); - assert(guardptr != NULL); - assert(guardptr != &__guard[0]); + for (i = 0; i < n; i++) + if (s[i] != 0) + return (1); + + return (0); +} + +static int foundldso = 0; + +static int +callback(struct dl_phdr_info *info, size_t size, void *cookie) +{ + int i; + int foundrandomize = 0; - guard = *guardptr; - assert(guard != 0); + assert(size >= sizeof(struct dl_phdr_info)); + if (strcmp(info->dlpi_name, "/usr/libexec/ld.so") != 0) + return (0); + foundldso = 1; + + for (i = 0; i < info->dlpi_phnum; i++) + if (info->dlpi_phdr[i].p_type == PT_OPENBSD_RANDOMIZE) { + foundrandomize = 1; + assert(nonzero((char *)(info->dlpi_phdr[i].p_vaddr + + info->dlpi_addr), info->dlpi_phdr[i].p_memsz)); + } + + assert(foundrandomize); + return (0); +} + +int +main() +{ + dl_iterate_phdr(callback, NULL); + assert(foundldso); return (0); } |