From 3b3f5a12fce4ccb5c09b4201aa93e3e17adf024c Mon Sep 17 00:00:00 2001 From: Hajime Yoshimori Date: Fri, 1 May 2020 21:14:32 +0900 Subject: [PATCH 1/3] check return value of dladdr --- src/dladdr.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dladdr.c b/src/dladdr.c index fef32579..3dffdb3f 100644 --- a/src/dladdr.c +++ b/src/dladdr.c @@ -36,11 +36,13 @@ wrapper(dladdr, int, (const void * addr, Dl_info * info)) ret = nextcall(dladdr)(addr, info); - if (info->dli_fname) { - narrow_chroot_path(info->dli_fname); - } - if (info->dli_sname) { - narrow_chroot_path(info->dli_sname); + if (ret != 0) { + if (info->dli_fname) { + narrow_chroot_path(info->dli_fname); + } + if (info->dli_sname) { + narrow_chroot_path(info->dli_sname); + } } return ret; From 2411c281cc8647ac7264d8ce370d3b691fbb9ada Mon Sep 17 00:00:00 2001 From: Hajime Yoshimori Date: Fri, 12 Nov 2021 23:36:37 +0900 Subject: [PATCH 2/3] Add test case --- test/Makefile.am | 1 + test/src/Makefile.am | 1 + test/src/test-dladdr.c | 14 ++++++++++++++ test/t/dladdr.t | 14 ++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 test/src/test-dladdr.c create mode 100644 test/t/dladdr.t diff --git a/test/Makefile.am b/test/Makefile.am index aba29538..0021b0a1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -9,6 +9,7 @@ TESTS = \ t/cmd-subst.t \ t/cp.t \ t/dedotdot.t \ + t/dladdr.t \ t/execlp.t \ t/execve-elfloader.t \ t/execve-null-envp.t \ diff --git a/test/src/Makefile.am b/test/src/Makefile.am index 7fb3075b..5f5fde8d 100644 --- a/test/src/Makefile.am +++ b/test/src/Makefile.am @@ -3,6 +3,7 @@ check_PROGRAMS = \ test-chroot \ test-clearenv \ test-dedotdot \ + test-dladdr \ test-execlp \ test-execve-null-envp \ test-fts \ diff --git a/test/src/test-dladdr.c b/test/src/test-dladdr.c new file mode 100644 index 00000000..5ec8d248 --- /dev/null +++ b/test/src/test-dladdr.c @@ -0,0 +1,14 @@ +#define _GNU_SOURCE +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + Dl_info info; + memset(&info, 0xfe, sizeof(info)); /* fill with inaccessible address */ + int ret = dladdr(NULL, &info); + printf("%ld\n", ret); + return 0; +} diff --git a/test/t/dladdr.t b/test/t/dladdr.t new file mode 100644 index 00000000..fc7f9397 --- /dev/null +++ b/test/t/dladdr.t @@ -0,0 +1,14 @@ +#!/bin/sh + +srcdir=${srcdir:-.} +. $srcdir/common.inc.sh + +prepare 1 + +PATH=$srcdir/bin:$PATH + +t=`$srcdir/fakechroot.sh $testtree /bin/test-dladdr` +[ "$t" != "0" ] && not +ok "dladdr returns" $t + +cleanup From c1efe8a2a9bba711797233bb4c2df55556f0ebcd Mon Sep 17 00:00:00 2001 From: Hajime Yoshimori Date: Thu, 25 Aug 2022 20:44:26 +0900 Subject: [PATCH 3/3] Add executable bit --- test/t/dladdr.t | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/t/dladdr.t diff --git a/test/t/dladdr.t b/test/t/dladdr.t old mode 100644 new mode 100755