https://sourceware.org/bugzilla/show_bug.cgi?id=17556

Maximilian Schneider <max at schneidersoft dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |max at schneidersoft dot net

--- Comment #6 from Maximilian Schneider <max at schneidersoft dot net> ---
The following is a way to reproduce a similar problem exposing issues in the
way gdb handles malformed elf files. in this case: A non-allocatable `.text`
with a load address.

```
# make test script
cat > flip.py <<'SENTINEL'
#!/usr/bin/env python3
"""Flip the ELF64 .text section flags between AX(6) and WX(5) — the GDB.md
bug."""
import struct, sys

path = sys.argv[1]
new_flags = int(sys.argv[2], 0)  # 5 = W|X (buggy), 6 = A|X (fixed)

with open(path, "rb") as f:
    data = bytearray(f.read())

# ELF64 header
e_shoff, = struct.unpack_from("<Q", data, 0x28)
e_shentsize, e_shnum, e_shstrndx = struct.unpack_from("<HHH", data, 0x3A)

def shdr(i):
    o = e_shoff + i * e_shentsize
    name, stype, flags, addr, off, size = struct.unpack_from("<IIQQQQ", data,
o)
    return o, name, stype, flags, off, size

_, _, _, _, stroff, strsize = shdr(e_shstrndx)
def cstr(off):
    end = data.index(b"\0", stroff + off)
    return data[stroff + off:end].decode()

for i in range(e_shnum):
    o, name, stype, flags, off, size = shdr(i)
    if cstr(name) == ".text":
        old = flags
        struct.pack_into("<Q", data, o + 0x08, new_flags)
        print(f".text sh_flags: {old:#x} -> {new_flags:#x}")
        break
else:
    sys.exit("no .text section")

with open(path, "wb") as f:
    f.write(data)

SENTINEL
# produce a valid executable
echo "int main(){ return 0;} " | gcc -g -x c -o test -
# flip the bit
python3 /tmp/opencode/flip_text_flags.py test 5
# watch gdb crash
gdb --batch -ex "b main" -ex "r" test
```

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to