From fb2e6d247a5f0fe1d94da241595f1f333f3f02e3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 25 Jul 2026 22:17:36 +0200 Subject: [PATCH] Fix an unwind-safety issue in openat If read_link_content were to unwind, dirfd would incorrectly get closed. (cherry picked from commit 8965d7fc89d35e247d76e40cfabbce488f66f25f) --- src/platform/redox/path.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/platform/redox/path.rs b/src/platform/redox/path.rs index 51dadb3a03..95315b4436 100644 --- a/src/platform/redox/path.rs +++ b/src/platform/redox/path.rs @@ -2,6 +2,7 @@ use alloc::{borrow::Cow, string::ToString}; use arrayvec::ArrayString; use core::{ ffi::c_int, + mem::ManuallyDrop, str::{self, FromStr}, }; use redox_path::{RedoxReference, RedoxStr}; @@ -235,9 +236,9 @@ pub fn openat(dirfd: c_int, path: RedoxStr<'_>, flags: usize) -> Result { let link_path = read_link_content(None, &path, true); (link_path, dirfd) } else { - let fd = FdGuard::new(dirfd as usize); + let fd = ManuallyDrop::new(FdGuard::new(dirfd as usize)); let link_path = read_link_content(Some(&fd), &path, true); - (link_path, fd.take() as i32) + (link_path, ManuallyDrop::into_inner(fd).take() as i32) }; let link_path = openat2_path(dirfd, link_path?, 0)?; resolve_sym_links(link_path, flags)