Assure fwrite() and fclose() only work if FD>=3, exit with -9 (EBADF) otherwise

This commit is contained in:
2025-06-25 10:02:59 +02:00
parent 3cbf9e8ce0
commit c4ce3212e7

View File

@ -86,9 +86,17 @@ fclose:
push rbp
mov rbp, rsp
cmp rdi, 3
jl .ebadf
mov rax, NR_close
syscall
jmp .quit
.ebadf:
mov rax, -9
.quit:
leave
ret
;----- fwrite(FILE* fp, char* str) -----;
@ -98,6 +106,9 @@ fwrite:
push rbp
mov rbp, rsp
cmp rdi, 3
jl .ebadf
mov r9, rdi
mov rdi, rsi
call strlen
@ -105,6 +116,11 @@ fwrite:
mov rax, NR_write
mov rdi, r9
syscall
jmp .quit
.ebadf:
mov rax, -9
.quit:
leave
ret