How to avoid stdin input that does not fit in buffer be sent to the shell in Linux 64-bit Intel (x86-64) assembly

前端 未结 3 1277
一向
一向 2021-01-13 15:44

Edit: Title changed, as @Gunner pointed out that this is not a buffer overflow.

In reading user input from stdin with NR_read

相关标签:
3条回答
  • 2021-01-13 16:09

    You could read the input until newline character is found.

    0 讨论(0)
  • 2021-01-13 16:14

    It is not a buffer overflow as others have stated. I wrote a tutorial on reading from the terminal in Linux which also shows how to deal with this issue. It uses Int 80, but you can easily change it to fit your needs.

    http://www.dreamincode.net/forums/topic/286248-nasm-linux-terminal-inputoutput-wint-80h/

    0 讨论(0)
  • 2021-01-13 16:27

    The read syscall already has that protection built in. One other thing though: You shouldn't be explicitly using syscall. What if your code is taken to an x86-64 machine (which uses sysenter)? You should be using Linux's VDSO (virtual dynamic shared object), which contains code to do syscalls on all architectures, regardless as to wheather they support syscall, sysenter, or only int.

    0 讨论(0)
提交回复
热议问题