Skip to content

Commit

Permalink
preload: Wrap __getcwd_chk()
Browse files Browse the repository at this point in the history
Fixes operation with glibc-2.36.9000-24.fc38 in Fedora rawhide.
  • Loading branch information
martinpitt committed Jan 29, 2023
1 parent 13b8396 commit 9fcfb4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/libumockdev-preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test-static-code
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9fcfb4e

Please sign in to comment.