gpt4 book ai didi

linux - 当缓冲区溢出时,sys_read 将是 "spill"个字符

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:03:59 26 4
gpt4 key购买 nike

在 Linux x86 上使用 NASM

mov ecx,eax
mov edx,ebx
mov eax,3
mov ebx,0
int 80h
ret

EAX 最初有一个mov'd db 常量,EBX 有缓冲区的长度

这是我用来从控制台读取的代码。它工作正常,除了一个问题......我要求 2 个字符,如果我超过 2 个字符并按 enter,下次我要求输入时,那些“溢出”/额外的字符将立即输入该请求,没有用户交互。如果我再次要求输入失败,这些额外的字符将立即被 shell 解释为命令。

例子:

对该读取例程的 2 次后续调用将产生:

2345

第二个输入请求既不会阻塞也不会提示用户输入任何内容,它只接受任何可能的字符。在这两种情况下,我都要求在一个用零填充的 3 字节缓冲区上准确地输入两个字符。

1 调用读取例程:

2345
$> 45: command not found

关于如何解决这个问题的任何想法?我应该使用不同的系统调用吗?

最佳答案

读取输入后,您需要刷新缓冲区以避免多余的部分传递给下一个输入读取。不过,这不是缓冲区溢出。

我问过同样的问题,但对于 x86-64 Linux,所以它并不完全重复: How to avoid stdin input that does not fit in buffer be sent to the shell in Linux 64-bit Intel (x86-64) assembly

无论如何,遵循 GunnerInc 的优秀教程(适用于 x86 Linux)应该可以解决您的问题: http://www.dreamincode.net/forums/topic/286248-nasm-linux-terminal-inputoutput-wint-80h/

关于linux - 当缓冲区溢出时,sys_read 将是 "spill"个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16092822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com