Jump distance of jz command is short by 1
.lst
file resulting from compilation with nasm
assembler:
<code>268 00000108 7405 jz _child ; At 7405, it should not be able to jump to 0000010F.
269 0000010A E9F1FEFFFF jmp near _start
270
271 _child:
272 ; Call the getrandom system call
273 0000010F B83E010000 mov eax, 318 ; System call number for getrandom
</code>
<code>268 00000108 7405 jz _child ; At 7405, it should not be able to jump to 0000010F.
269 0000010A E9F1FEFFFF jmp near _start
270
271 _child:
272 ; Call the getrandom system call
273 0000010F B83E010000 mov eax, 318 ; System call number for getrandom
</code>
268 00000108 7405 jz _child ; At 7405, it should not be able to jump to 0000010F.
269 0000010A E9F1FEFFFF jmp near _start
270
271 _child:
272 ; Call the getrandom system call
273 0000010F B83E010000 mov eax, 318 ; System call number for getrandom
During debugging with gdb
:
<code>0x400178: 0x90 0x90 0x90 0x90 0x90 0x90 0x85 0xc0
0x400180: 0x74 0x05 0xe9 0xf1 0xfe 0xff 0xff 0xff
0x400188: 0xb8 0x3e 0x01 0x00 0x00 0xbf 0xfe 0x00
0x400190: 0x40 0x00 0xbe 0x00 0x01 0x00 0x00 0x31
0x400198: 0xd2 0x0f 0x05 0xe9 0xd9 0xfe 0xff 0xff
(gdb) stepi
0x0000000000400180 in ?? ()
(gdb) info registers
(omitted)
rip 0x400180 0x400180
eflags 0x246 [ PF ZF IF ]#Zero flag is set.
(omitted)
(gdb) stepi
0x0000000000400187 in ?? ()
(gdb) stepi
Thread 2.1 "ancestor" received signal SIGILL, Illegal instruction.
0x0000000000400187 in ?? ()
</code>
<code>0x400178: 0x90 0x90 0x90 0x90 0x90 0x90 0x85 0xc0
0x400180: 0x74 0x05 0xe9 0xf1 0xfe 0xff 0xff 0xff
0x400188: 0xb8 0x3e 0x01 0x00 0x00 0xbf 0xfe 0x00
0x400190: 0x40 0x00 0xbe 0x00 0x01 0x00 0x00 0x31
0x400198: 0xd2 0x0f 0x05 0xe9 0xd9 0xfe 0xff 0xff
(gdb) stepi
0x0000000000400180 in ?? ()
(gdb) info registers
(omitted)
rip 0x400180 0x400180
eflags 0x246 [ PF ZF IF ]#Zero flag is set.
(omitted)
(gdb) stepi
0x0000000000400187 in ?? ()
(gdb) stepi
Thread 2.1 "ancestor" received signal SIGILL, Illegal instruction.
0x0000000000400187 in ?? ()
</code>
0x400178: 0x90 0x90 0x90 0x90 0x90 0x90 0x85 0xc0
0x400180: 0x74 0x05 0xe9 0xf1 0xfe 0xff 0xff 0xff
0x400188: 0xb8 0x3e 0x01 0x00 0x00 0xbf 0xfe 0x00
0x400190: 0x40 0x00 0xbe 0x00 0x01 0x00 0x00 0x31
0x400198: 0xd2 0x0f 0x05 0xe9 0xd9 0xfe 0xff 0xff
(gdb) stepi
0x0000000000400180 in ?? ()
(gdb) info registers
(omitted)
rip 0x400180 0x400180
eflags 0x246 [ PF ZF IF ]#Zero flag is set.
(omitted)
(gdb) stepi
0x0000000000400187 in ?? ()
(gdb) stepi
Thread 2.1 "ancestor" received signal SIGILL, Illegal instruction.
0x0000000000400187 in ?? ()
As shown, it is not functioning correctly. It should jump to 0x0000000000400188
. Is nasm
assembler causing a bug?
jz _child must be compiled to 7406
New contributor
dayo tokumei is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1