From 9fcfb4e645aaa2b79c1ec6ed85ca59d74113f3e5 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sun, 29 Jan 2023 16:56:44 +0100 Subject: [PATCH] preload: Wrap __getcwd_chk() Fixes operation with glibc-2.36.9000-24.fc38 in Fedora rawhide. --- src/libumockdev-preload.c | 18 ++++++++++++++++++ tests/test-static-code | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libumockdev-preload.c b/src/libumockdev-preload.c index 7340e12c..db6e310c 100644 --- a/src/libumockdev-preload.c +++ b/src/libumockdev-preload.c @@ -1633,6 +1633,24 @@ getcwd(char *buf, size_t size) return r; } +char * __getcwd_chk(char *buf, size_t size, size_t buflen); +char * +__getcwd_chk(char *buf, size_t size, size_t buflen) +{ + libc_func (__getcwd_chk, char*, char*, size_t, size_t); + const char *prefix = getenv("UMOCKDEV_DIR"); + char *r = ___getcwd_chk (buf, size, buflen); + + if (prefix != NULL && r != NULL) { + size_t prefix_len = strlen (prefix); + if (strncmp (r, prefix, prefix_len) == 0) { + DBG(DBG_PATH, "testbed wrapped __getcwd_chk: %s -> %s\n", r, r + prefix_len); + memmove(r, r + prefix_len, strlen(r) - prefix_len + 1); \ + } + } + return r; +} + ssize_t read(int fd, void *buf, size_t count) { diff --git a/tests/test-static-code b/tests/test-static-code index a527f1f3..5477cdd4 100755 --- a/tests/test-static-code +++ b/tests/test-static-code @@ -38,7 +38,7 @@ R=$(echo "$CODE_WRAPPERS" | $GREP -B1 '^[a-z_]\+(' | awk 'BEGIN { RS="--\n" } / check_empty "$R" "preload libc wrapped code part has non-exported function(s)" # wrappers must not have a '_' in the name, libc doesn't use that style -R=$(echo "$LIBC_OVERRIDES" | grep _ | grep -v inotify_add_watch || true) +R=$(echo "$LIBC_OVERRIDES" | grep _ | grep -Ev 'inotify_add_watch|__getcwd_chk' || true) check_empty "$R" "preload libc wrapped code part exports function with '_'" # must not use wrapped functions in internal logic