-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a checked subtraction to `fd_seek` so that passing in a large negative offset does not underflow. fixes #4589
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::os::fd::AsRawFd; | ||
|
||
#[link(wasm_import_module = "wasi_snapshot_preview1")] | ||
extern "C" { | ||
pub fn fd_seek(fd: i32, offset: i64, whence: i32, filesize: i32) -> i32; | ||
} | ||
|
||
const ERRNO_INVAL: i32 = 28; | ||
|
||
const WHENCE_CUR: i32 = 1; | ||
|
||
fn main() { | ||
unsafe { | ||
let large_negative_offset = -6551085931117533355; | ||
let mut filesize = 0u64; | ||
|
||
let f = std::fs::OpenOptions::new() | ||
.read(true) | ||
.write(true) | ||
.create(true) | ||
.open("test.sh") | ||
.unwrap(); | ||
let errno = fd_seek( | ||
f.as_raw_fd(), | ||
large_negative_offset, | ||
WHENCE_CUR, | ||
&mut filesize as *mut u64 as usize as i32, | ||
); | ||
|
||
assert_eq!(errno, ERRNO_INVAL); | ||
} | ||
} |