Skip to content

Commit 334fa6f

Browse files
copilot
1 parent 696122e commit 334fa6f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kernel/src/filesystem/vfs/syscall/sys_pread64.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ impl Syscall for SysPread64Handle {
4242
}
4343

4444
// 检查offset + len是否溢出
45-
if offset.checked_add(len).is_none() || offset > i64::MAX as usize {
45+
46+
let end_pos = offset.checked_add(len).ok_or(SystemError::EINVAL)?;
47+
if offset > i64::MAX as usize || end_pos > i64::MAX as usize {
4648
return Err(SystemError::EINVAL);
4749
}
4850

@@ -62,7 +64,10 @@ impl Syscall for SysPread64Handle {
6264

6365
// 检查是否是管道/Socket (ESPIPE)
6466
let md = file.metadata()?;
65-
if md.file_type == FileType::Pipe || md.file_type == FileType::Socket {
67+
if md.file_type == FileType::Pipe
68+
|| md.file_type == FileType::Socket
69+
|| md.file_type == FileType::CharDevice
70+
{
6671
return Err(SystemError::ESPIPE);
6772
}
6873

0 commit comments

Comments
 (0)