I am learning NASM and couldn't figure out why the following snippet runs without crashing.
2 bytes were reserved for sinput
buffer and yet, it seems that we can write 3 bytes into it. How is it possible ?
global _start
section .text
_start:
mov eax, 3 ; invoke SYS_READ (opcode 3)
mov ebx, 0 ; write to STDIN
mov ecx, sinput ; reserved space to store our input (known as a buffer)
mov edx, 3 ; number of bytes to read
int 80h
; WHY DOESNT IT CRASH ? Yet, we wrote 3 bytes into our sinput buffer but initially reserved 2 bytes.
mov ebx, [ecx]
mov ebx, [ecx + 1]
mov ebx, [ecx + 2]
mov eax, 1 ; SYS_EXIT
mov ebx, 0
int 80h
section .bss
sinput: resb 2 ; reserve a 2 byte space in memory for the users input string