From 41dc3143da3745f5da87f72b73ab16b4b4b9c5cf Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia Date: Tue, 25 Mar 2025 17:13:39 +0100 Subject: [PATCH 1/2] Implemented improvements but real bug is not solved. --- .dockerignore | 15 +++++++++++++++ Dockerfile | 34 ++++++++++++++++++++++++++++++++++ plthook_elf.c | 4 ++-- test/testprog.c | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f011ba0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +** +!plthook_elf.c +!plthook_osx.c +!plthook_win32.c +!plthook.h +!test +test/*.obj +test/libtest.dll +test/libtest.exp +test/libtest.lib +test/libtest.so +test/testprog +test/testprog.exe +test/dummy.c +test/dummy.o diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1f7663d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# Dockerfile for QEMU testing +FROM ubuntu:latest + +RUN apt update \ + && apt install -y \ + make \ + qemu-user \ + gcc-arm-linux-gnueabi \ + gcc-arm-linux-gnueabihf \ + gcc-aarch64-linux-gnu \ + gcc-powerpc-linux-gnu \ + gcc-powerpc64le-linux-gnu \ + gcc-riscv64-linux-gnu \ + libc6-dev-armhf-cross \ + libc6-dev-ppc64el-cross \ + libc6-dev-powerpc-cross \ + libc6-dev-armel-cross \ + libc6-dev-arm64-cross + +WORKDIR /plthook + +COPY . . + +WORKDIR /plthook/test + +ENV OPT_CFLAGS="-O3" + +RUN echo "Running tests" \ + && make relro_pie_tests TARGET_PLATFORM=aarch64-linux-gnu \ + && make relro_pie_tests TARGET_PLATFORM=arm-linux-gnueabi \ + && make relro_pie_tests TARGET_PLATFORM=arm-linux-gnueabihf \ + && make relro_pie_tests TARGET_PLATFORM=powerpc-linux-gnu QEMU_ARCH=ppc \ + && make relro_pie_tests TARGET_PLATFORM=powerpc64le-linux-gnu QEMU_ARCH=ppc64le \ + && make relro_pie_tests TARGET_PLATFORM=riscv64-linux-gnu QEMU_ARCH=riscv64 diff --git a/plthook_elf.c b/plthook_elf.c index ac30d08..9885ed0 100644 --- a/plthook_elf.c +++ b/plthook_elf.c @@ -683,14 +683,14 @@ static int plthook_open_real(plthook_t **plthook_out, struct link_map *lmap) set_errmsg("failed to find PLT_DT_RELSZ"); return PLTHOOK_INTERNAL_ERROR; } - total_size = dyn->d_un.d_ptr; + total_size = dyn->d_un.d_val; dyn = find_dyn_by_tag(lmap->l_ld, PLT_DT_RELENT); if (dyn == NULL) { set_errmsg("failed to find PLT_DT_RELENT"); return PLTHOOK_INTERNAL_ERROR; } - elem_size = dyn->d_un.d_ptr; + elem_size = dyn->d_un.d_val; plthook.rela_dyn_cnt = total_size / elem_size; } #endif diff --git a/test/testprog.c b/test/testprog.c index a399b01..370f2d9 100644 --- a/test/testprog.c +++ b/test/testprog.c @@ -90,7 +90,7 @@ static void reset_result(void) static void set_result(hooked_val_t *hv, const char *str, double result) { - strncpy(hv->str, str, sizeof(hv->str)); + strncpy(hv->str, str, sizeof(hv->str) - 1); hv->result = result; } From 7f5993944b9df6ccaac9138a0e60ff35c3b960a4 Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia Date: Tue, 25 Mar 2025 17:23:56 +0100 Subject: [PATCH 2/2] Add docker command for testing. --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 1f7663d..a4c58c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ # Dockerfile for QEMU testing +# docker build -t metacall/plthook . FROM ubuntu:latest RUN apt update \