Search code examples
cx86heap-memoryelfld-preload

How to apply LD_PRELOAD only to target program?


I am trying to debug a Heap Corruption (using the QIRA Debugger); that only works with Doug Lea's Malloc.

I have tried doing the following:

LD_PRELOAD=./malloc.so qira ./program $(cat shfree5)

I get the following error:

ERROR: ld.so: object './malloc.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.

which happens because the loader tries linking an x86 malloc.so to an x64 qira.

I want to apply the LD_PRELOAD only to ./program, not to qira; I have tried with the env command, but can not make it to work.

Thanks in advance!


Solution

  • It looks like you can set QEMU_SET_ENV=LD_PRELOAD=./malloc.so in the environment to affect the process.

    I'll note that you can similarly unset environment variables for the target by setting QEMU_UNSET_ENV=FOO,BAR.