From 3d10ced4e50ce3024992d14ba3e0b97042e83b7c Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 4 Jan 2024 09:56:08 +0000 Subject: [PATCH] return an error number if unwrapping of CreationOption fails --- src/fd/mod.rs | 5 ++--- src/syscalls/mod.rs | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/fd/mod.rs b/src/fd/mod.rs index bc27670f4a..752ad03ded 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -252,8 +252,8 @@ pub(crate) fn open(name: &str, flags: i32, mode: i32) -> Result Result Result { debug!("Open directory {}", name); diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index f70c1c4819..ed94d6b54f 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -119,11 +119,16 @@ pub extern "C" fn sys_unlink(name: *const u8) -> i32 { extern "C" fn __sys_mkdir(name: *const u8, mode: i32) -> i32 { let name = unsafe { CStr::from_ptr(name as _) }.to_str().unwrap(); + let mode = if let Some(mode) = CreationMode::from_bits(mode) { + mode + } else { + return -crate::errno::EINVAL; + }; fs::FILESYSTEM .get() .unwrap() - .mkdir(name, CreationMode::from_bits(mode).unwrap()) + .mkdir(name, mode) .map_or_else(|e| -num::ToPrimitive::to_i32(&e).unwrap(), |_| 0) }