i was trying to make a simple little password program (to further expand my knowledge) and i just can’t get it to work. the problem is even though i enter the correct password it will not jump to the label “good”.
my way of validating the password is to xor the built in password with the user submitted one and if it returns 0 that means they are the same. (because anything xor’d by itself is 0)
so my mistake is most likely within the cmpl and je commands or within my xoring itself. any help would be nice i simply can’t find my mistake.
.section .data
hmm:
.ascii "Enter the password\n\0"
password:
.ascii "abgirl"
success:
.ascii "Password is right\n\0"
bad:
.ascii "password is wrong\n\0"
.section .bss
.equ buffer_size, 500
.lcomm buffer_data, buffer_size
.section .text
.global _start
_start:
pushl $hmm
call printf #print $hmm
movl $0, %ebx
movl $buffer_data, %ecx
movl $buffer_size, %edx
movl $3, %eax
int $0x80 #get user input
movl $password, %eax
xorl $buffer_data, %eax #xor the passwords (value stored in eax)
cmpl $0, %eax #compare
je good #jump if equal
pushl $bad
call printf #print bad pass if not equal
jmp end #jump to exit
good:
pushl $success
call printf #print $success
end:
movl $0, %ebx
movl $1, %eax
int $0x80 #cleanup and exit
Your problem is the comparison.
The dollar signs mean you are working with the addresses of the variables, not the contents. Since the password and buffer are at different locations, the comparison will always be false. What you want is to compare the character in each position of the password and buffer. To do this, you will need to know how long the password is.
Notice that I also added a null byte to your password, so that the comparison will fail if the input password is longer. Now, you need to change your comparison to check each byte.