LIEF: add segment/section to ELF causes ld segfault

Describe the bug I tried to add a segment or section like below, but ld crashed when loading the elf. Both pie and no-pie elf crashed.

To Reproduce Steps to reproduce the behavior:

    s           = lief.ELF.Segment()
    s.type      = lief.ELF.SEGMENT_TYPES.LOAD
    s.content   = [0x90 for i in range(0x100)]
    s.alignment = 0x1000
    s.add(lief.ELF.SEGMENT_FLAGS.R)
    s.add(lief.ELF.SEGMENT_FLAGS.X)
    s = target.add(s)

Expected behavior No crash.

Environment (please complete the following information):

  • System and Version : Ubuntu 20.04, 64bit, ld version is 2.31
  • Target format : ELF
  • LIEF commit version: 0.10.1-bfe5414

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (12 by maintainers)

Most upvoted comments

Happy to say that this issue is now fixed 🚀

@romainthomas I wanted to share that I think it works… to be honest I don’t have the greatest tests and it was just all by hand. I am not longer facing the SEGFAULT where I was before – but that’s not clear I didn’t yet find any new ones 😉

For those that are curious how I did it – please take a look at https://github.com/fzakaria/shrinkwrap/pull/5 That was me using Poetry and pulling in the latest commit for lief.