Commit 4d8fd022 authored by Ramon Nou's avatar Ramon Nou
Browse files

fix relativize_fd with nullptr

parent 28560304
Loading
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -317,13 +317,27 @@ PreloadContext::relativize_fd_path(int dirfd, const char* raw_path,
    // If we run the constructor we also already setup the mountdir
    assert(!mountdir_.empty());

    // Handle nullptr path: this is a valid POSIX scenario when AT_EMPTY_PATH is
    // set (e.g. statx/openat on a bare fd). Resolve dirfd to determine scope:
    //  - GekkoFS fd  → return its stored path as internal
    //  - external/unknown fd → return fd_unknown so the hook forwards to kernel
    if(raw_path == nullptr) {
        if(dirfd != AT_FDCWD && ofm_->exist(dirfd)) {
            relative_path = ofm_->get(dirfd)->path();
            return RelativizeStatus::internal;
        }
        // dirfd is either AT_FDCWD (which requires a valid path) or an
        // external fd — let the kernel handle it.
        return RelativizeStatus::fd_unknown;
    }

    // Skips paths that are used on locking places (i.e. java
    // /proc/sys/vm/overcommit_memory) and produces deadlocks as we call malloc
    // inside.
    if(dirfd == AT_FDCWD) {
        for(auto& excl_path : gkfs::path::excluded_paths) {
            // compare raw_path with excl_path
            if(raw_path != nullptr && raw_path[0] == gkfs::path::separator) {
            if(raw_path[0] == gkfs::path::separator) {
                if(strncmp(raw_path + 1, excl_path.c_str(),
                           excl_path.length()) == 0) {
                    return RelativizeStatus::external;
@@ -335,7 +349,7 @@ PreloadContext::relativize_fd_path(int dirfd, const char* raw_path,

    std::string path;

    if(raw_path != nullptr && raw_path[0] != gkfs::path::separator) {
    if(raw_path[0] != gkfs::path::separator) {
        // path is relative
        if(dirfd == AT_FDCWD) {
            // path is relative to cwd