From a9f05d3c3c21ef0bc9855a3175d0b6d70cb1ccdb Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 12 Sep 2024 11:41:39 +0200 Subject: [PATCH] Add trailing NUL byte check on Redox. --- src/platform/redox/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 96154409b2..181fab50e9 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -428,6 +428,12 @@ impl Pal for Sys { unsafe fn dent_reclen_offset(this_dent: &[u8], offset: usize) -> Option<(u16, u64)> { let mut header = DirentHeader::default(); header.copy_from_slice(&this_dent.get(..size_of::())?); + + // If scheme does not send a NUL byte, this shouldn't be able to cause UB for the caller. + if this_dent.get(usize::from(header.record_len) - 1) != Some(&b'\0') { + return None; + } + Some((header.record_len, header.next_opaque_id)) }