F
F
fsociety_one2020-06-24 22:27:09
assembler
fsociety_one, 2020-06-24 22:27:09

Why does the kernel crash when writing to an array?

Hello everyone, I have a problem. There is a code in the program:

field db '1', '2', '3', '4', '5', '6', '7', '8', '9'
move resb 1

_move:
        mov	edx, 1
        mov	ecx, move 
        mov	ebx, 1
        mov	eax, 4
        int	0x80

        mov     eax, move
        mov     ebx, field
        add      ebx, eax

        call     _clear

        mov     [ebx], byte 'X'

        ret

Empirically, I learned that call _clear is executed, but when 'X' is inserted into [ebx], it crashes with the message:
23988 segmentation fault (core dumped)
Move receives a number using input, the program asks for it, and the user enters a number from 1 up to 9
If instead of a string:
add ebx, eax
Write:
add ebx, 2
Then everything is correctly executed, as I suspect, the problem is that the input from the string is not a number, but an ASCII character, but I don’t know how to process it and in general , is it so, I hope for your help, thanks!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
galaxy, 2020-06-24
@galaxy

I suspect the problem is that the input from the string is not a number, but an ASCII character

Why suspect, look at the debugger.
There is another problem here: move is 1 byte, and in eax you fuss (and then add) 4. Of course, there is garbage

N
none7, 2020-06-26
@none7

mov     eax, move
mov     ebx, field

Is it an assignment of pointers to variables? And then adding two pointers and writing to this garbage? Maybemovzx eax, byte ptr [move]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question