From 741c1ef7a4f2ac316ad6e557ddbe03023413478d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 May 2024 04:22:06 +0200 Subject: Adding upstream version 1:4.5. Signed-off-by: Daniel Baumann --- tests/common/link_failure.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/common/link_failure.c (limited to 'tests/common/link_failure.c') diff --git a/tests/common/link_failure.c b/tests/common/link_failure.c new file mode 100644 index 0000000..8cf460a --- /dev/null +++ b/tests/common/link_failure.c @@ -0,0 +1,51 @@ +/* + * gcc link_failure.c -o link_failure.so -shared -ldl + * LD_PRELOAD=./link_failure.so FAILURE_PATH=/etc/shadow ./test /etc/shadow + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +typedef int (*link_type) (const char *oldpath, const char *newpath); +static link_type next_link; + +static const char *failure_path = NULL; + +int link (const char *oldpath, const char *newpath) +{ + if (NULL == next_link) + { + next_link = dlsym (RTLD_NEXT, "link"); + assert (NULL != next_link); + } + if (NULL == failure_path) { + failure_path = getenv ("FAILURE_PATH"); + if (NULL == failure_path) { + fputs ("No FAILURE_PATH defined\n", stderr); + } + } + + if ( (NULL != newpath) + && (NULL != failure_path) + && (strcmp (newpath, failure_path) == 0)) + { + fprintf (stderr, "link FAILURE %s %s\n", oldpath, newpath); + errno = EIO; + return -1; + } + + return next_link (oldpath, newpath); +} + -- cgit v1.2.3