$ gdb -q -batch -ex 'set debuginfod enabled off' \
what it printed on the machine that wrote this lab
-ex 'break 132' -ex run -ex 'print p' \
-ex 'print/x *(unsigned char*)p' -ex 'info locals' \
./bin/02_uninit_wild_ptr
Breakpoint 1, main () at 02_uninit_wild_ptr.c:132
132 unsigned char v = *(unsigned char *)p; // <-- THE BUG
$1 = 0x7fffffffd718 "\030\327\377\377\377\177"
$2 = 0x18
p = 0x7fffffffd718 "\030\327\377\377\377\177"
v = 0 '\000'
Run that gdb line TWICE: `print p` shows the SAME address both times,
because gdb sets `disable-randomization on` by default:
$ gdb -q -batch -ex 'show disable-randomization' ./bin/02_uninit_wild_ptr
what it printed on the machine that wrote this lab
Disabling randomization of debuggee's virtual address space is on.
CONSEQUENCE: addresses are STABLE under gdb but DIFFER from a bare native
run (where ASLR is on). So "the address gdb shows" is not "the address
you crashed at natively". To reproduce the native layout under gdb:
(gdb) set disable-randomization off
How to read the commands:
break LINE -> stop just before the deref so we can inspect p.
print p -> the wild pointer's value (a random stack address).
print/x *(...)p -> the byte we are about to return, in hex.
info locals -> shows p (and v, still garbage) in this frame.