Edit: Title changed, as @Gunner pointed out that this is not a buffer overflow.
In reading user input from stdin
with NR_read
You could read the input until newline character is found.
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/
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
.