Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test case ut_lind_fs_mmap_invalid_offset_len #62

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/tests/fs_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,22 +582,25 @@ pub mod fs_tests {
//are invalid for the object specified by `fildes`` error.

/* Native linux will return EINVAL - TESTED locally */
assert_eq!(
cage.mmap_syscall(0 as *mut u8, 5, PROT_READ | PROT_WRITE, MAP_SHARED, fd, -10),
-(Errno::EINVAL as i32)
);

let result = cage.mmap_syscall(0 as *mut u8, 5, PROT_READ | PROT_WRITE, MAP_SHARED, fd, -10);
assert_eq!(result, -1, "Expected mmap to fail with -1 for negative offset");
// Verify errno is set to EINVAL
let errno = get_errno();
assert_eq!(errno, libc::EINVAL, "Expected errno to be EINVAL for negative offset");
//Checking if passing an offset that seeks beyond the end
//of the file correctly results in `Addresses in the
//range [off,off+len) are invalid for the object specified
//by `fildes`` error.

/* Native linux will return EINVAL - TESTED locally */
assert_eq!(
cage.mmap_syscall(0 as *mut u8, 5, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 25),
-(Errno::EINVAL as i32)
);

let result_beyond_eof = cage.mmap_syscall(0 as *mut u8, 5, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 25);
assert_eq!(result_beyond_eof, -1, "Expected mmap to fail with -1 for offset beyond EOF");

// Verify errno is set to EINVAL
let errno_beyond_eof = get_errno();
assert_eq!(errno_beyond_eof, libc::EINVAL, "Expected errno to be EINVAL for offset beyond EOF");
// Clean up and finalize
assert_eq!(cage.unlink_syscall(filepath), 0);
assert_eq!(cage.exit_syscall(libc::EXIT_SUCCESS), libc::EXIT_SUCCESS);
lindrustfinalize();
}
Expand Down
Loading