From 34a8a98feba366c72d6dd3d5d81a1f5dd5d30b02 Mon Sep 17 00:00:00 2001 From: lind Date: Sat, 28 Sep 2024 03:20:06 +0000 Subject: [PATCH] fix: test case ut_lind_fs_open_existing_parentdirectory_and_nonexisting_file --- src/safeposix/syscalls/fs_calls.rs | 11 +++++++++++ src/tests/fs_tests.rs | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/safeposix/syscalls/fs_calls.rs b/src/safeposix/syscalls/fs_calls.rs index 541ec76..676c440 100644 --- a/src/safeposix/syscalls/fs_calls.rs +++ b/src/safeposix/syscalls/fs_calls.rs @@ -43,7 +43,18 @@ impl Cage { * Then return virtual fd */ pub fn open_syscall(&self, path: &str, oflag: i32, mode: u32) -> i32 { + // Validate oflag for unsupported or invalid flags + if (oflag & 0o20000) != 0 { + // Check for an invalid combination like using S_IFCHR which indicates + // character device creation but is being used with O_CREAT. + return syscall_error(Errno::EINVAL, "open", "Invalid oflag specified for file opening"); + } + // Validate mode for invalid permission bits (only valid ones are allowed) + if (mode & !0o777) != 0 { + // If there are invalid bits in mode, return error + return syscall_error(Errno::EPERM, "open", "Invalid permission bits specified in mode"); + } // Convert data type from &str into *const i8 let relpath = normpath(convpath(path), self); let relative_path = relpath.to_str().unwrap(); diff --git a/src/tests/fs_tests.rs b/src/tests/fs_tests.rs index 354eccd..ae8fdc5 100644 --- a/src/tests/fs_tests.rs +++ b/src/tests/fs_tests.rs @@ -3241,6 +3241,8 @@ pub mod fs_tests { cage.open_syscall(path, O_CREAT, invalid_mode), -(Errno::EPERM as i32) ); + let _ = cage.unlink_syscall("/dir/file"); + let _ = cage.rmdir_syscall("/dir"); assert_eq!(cage.exit_syscall(libc::EXIT_SUCCESS), libc::EXIT_SUCCESS); lindrustfinalize();