flat assembler
Message board for the users of flat assembler.

Index > Linux > segmentation fault on calling atoi

Author
Thread Post new topic Reply to topic
gAr



Joined: 18 Apr 2010
Posts: 5
gAr 23 Jun 2010, 13:28
Hi,

I tried to convert the characters read from terminal to integer using atoi, but atoi is triggering a segmentation fault. What may be the cause? Is there any easier way to read from the terminal?

Code:
format ELF 

public  _start
extrn atoi
extrn exit

section '.data'
n dd 1
len=$-n


section '.text' executable



_start:
mov eax,3
mov ebx,0
mov ecx,n
mov edx,len
int 0x80      ;read system call

push 0
push [n]
call atoi
add esp,8

mov [n],eax

push 0
call exit    


./fasm atoi.asm atoi.o
ld -dynamic-linker /lib/ld-linux.so.2 -o atoi -lc atoi.o
Post 23 Jun 2010, 13:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 23 Jun 2010, 14:07
Try with:
Code:
;...
push 0
push n ;You want the address of n, not the contents.
call atoi
;...    
Post 23 Jun 2010, 14:07
View user's profile Send private message Visit poster's website Reply with quote
gAr



Joined: 18 Apr 2010
Posts: 5
gAr 23 Jun 2010, 14:20
Oh, thanks Smile

Didn't check that!!
Post 23 Jun 2010, 14:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.