Why does my assembly network server application cause a segmentation fault?

I'm working on a network server application in assembly language so I can understand low level networking concepts. So I've implemented a socket server using assembly language system calls, but I'm encountering a segmentation fault during execution. I have complied the binary on an Intel Core i7 12700K processor running Ubuntu 22.04 and the NASM assembler . I wander what is causing the segmentation fault ?
$ nasm -f elf32 socket.asm ; ld -m elf_i386 -o socket socket.o

$ ./socket

Segmentation fault (core dumped)
$ nasm -f elf32 socket.asm ; ld -m elf_i386 -o socket socket.o

$ ./socket

Segmentation fault (core dumped)
attachment 0
6 Replies
Enthernet Code
Enthernet Code3mo ago
@Marvee Amasi Since you compiled the code in 32-bit mode (-f elf32), re-check that your code is aligned with 32-bit conventions and that you aren’t inadvertently mixing 64-bit and 32-bit instructions or registers, Also to accurately diagnose this issue you should use tools like gdb to debug the binary and locate where the segmentation fault occurs and Identify the exact instruction causing the fault
gdb ./socket
(gdb) run
gdb ./socket
(gdb) run
Marvee Amasi
Marvee Amasi3mo ago
Thanks @Enthernet Code , so I used a debugger I have noticed that rip is overwritten with a not existent address. So I have added an exit at the end and now I do not receive any segmentation fault. I think I did the right thing
Marvee Amasi
Marvee Amasi3mo ago
mov eax, 0x1
mov ebx, 0x0
int 0x80
mov eax, 0x1
mov ebx, 0x0
int 0x80
Enthernet Code
Enthernet Code3mo ago
That's Nice @Marvee Amasi
Marvee Amasi
Marvee Amasi3mo ago
Thanks again , we could dodge using a debugger in many languages, but not assembly 😂
Want results from more Discord servers?
Add your server