fix(driver/tty): 修复 TTY 读取时的缓冲区偏移错误和规范模式语义问题 #1707
Merged
fslongjin merged 2 commits intoDragonOS-Community:masterfrom Jan 27, 2026
Merged
fix(driver/tty): 修复 TTY 读取时的缓冲区偏移错误和规范模式语义问题 #1707fslongjin merged 2 commits intoDragonOS-Community:masterfrom
fslongjin merged 2 commits intoDragonOS-Community:masterfrom
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix(driver/tty): 修复 TTY 读取时的缓冲区偏移错误和规范模式语义问题
概述
修复
TtyDevice::read_at中的两个关键 bug,这些 bug 导致在输入密码时触发 kernel panic("range end index out of range")。问题描述
Bug 1:
TtyDevice::read_at传递错误的缓冲区切片位置:
kernel/src/driver/tty/tty_device.rs错误代码:
问题: 传递整个
buf给 NTTY,但offset参数被累加。这导致:buf[0]buf[0]buf[0]buf[2]buf[0]buf[4]正确代码:
Bug 2:
canon_copy_from_read_buf返回值语义错误位置:
kernel/src/driver/tty/tty_ldisc/ntty.rs问题:
canon_copy_from_read_buf在请求满足时(nr=0)仍返回true,导致 NTTY 继续读取并累加额外的 offset。正确代码:
修复内容
文件 1:
kernel/src/driver/tty/tty_device.rs第 316 行:
说明:
&mut buf[offset..]而非整个bufoffset参数改为0(因为切片已经偏移)文件 2:
kernel/src/driver/tty/tty_ldisc/ntty.rscanon_copy_from_read_buf方法:说明:
nr=0(请求已满足)时返回false,即使缓冲区还有更多数据read()系统调用语义测试验证
修复前
修复后
影响范围
技术分析
为什么密码输入触发 bug 而正常命令不触发?
BorrowedCursorcapacity 为 1 的原因Rust 标准库
Buffer::read_more():当
filled = capacity - 1时,切片长度为 1,导致read(fd, ..., 1)。Review 检查清单
offset重置为0是正确的(切片已处理偏移)nr == 0返回false符合 POSIX 语义TtyDevice::write_at