{"record":{"id":"b671bd1eac833829","repo":"uutils/coreutils","slug":"invalid-file-descriptor","errorCode":null,"errorMessage":"invalid file descriptor","messagePattern":"invalid file descriptor","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/uucore/src/lib/features/safe_traversal.rs","lineNumber":467,"sourceCode":"                source: err,\n            }\n            .into());\n        }\n        Ok(())\n    }\n\n    /// Open a file for writing relative to this directory\n    /// Creates the file if it doesn't exist, truncates if it does\n    pub fn open_file_at(&self, name: &OsStr) -> io::Result<fs::File> {\n        let name_cstr =\n            CString::new(name.as_bytes()).map_err(|_| SafeTraversalError::PathContainsNull)?;\n        // O_NOFOLLOW: `openat` anchors the *directory*, not the final component,\n        // so without it a symlink planted at `name` is still followed and its\n        // target truncated. Callers reach here right after unlinking `name`,\n        // which is precisely the window an attacker races.\n        let flags = OFlag::O_CREAT\n            | OFlag::O_WRONLY\n            | OFlag::O_TRUNC\n            | OFlag::O_CLOEXEC\n            | OFlag::O_NOFOLLOW;\n        let mode = Mode::from_bits_truncate(0o666); // Default file permissions\n\n        let fd: OwnedFd = openat(self.fd.as_fd(), name_cstr.as_c_str(), flags, mode)\n            .map_err(|e| io::Error::from_raw_os_error(e as i32))?;\n\n        Ok(fs::File::from(fd))\n    }\n\n    /// Create a DirFd from an existing file descriptor (takes ownership)\n    pub fn from_raw_fd(fd: RawFd) -> io::Result<Self> {\n        if fd < 0 {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidInput,\n                translate!(\"safe-traversal-error-invalid-fd\"),\n            ));\n        }","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/uutils/coreutils/blob/85295bbf788bfd7a6926ba692031563504b304b7/src/uucore/src/lib/features/safe_traversal.rs#L449-L485","documentation":"Error \"invalid file descriptor\" thrown in uutils/coreutils.","triggerScenarios":"Occurs during safe directory traversal when a file descriptor becomes invalid (EBADF), e.g. closed concurrently.","commonSituations":"Traversal racing with another thread/process closing descriptors, or use-after-close in directory walking.","solutions":["Ensure the file descriptor is still open when used; do not close it before traversal completes.","Open the directory with the correct flags so the descriptor is valid for *at syscalls."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"85295bbf788bfd7a6926ba692031563504b304b7","analyzedAt":"2026-08-19T21:43:27.871Z","contentChangedAt":"2026-08-19T21:43:27.871Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}