Skip to content

Last entry in .data section content is not updated to new offset when segment is added #418

Closed
@pdreiter

Description

@pdreiter

Describe the bug
Content of .data section, when last 64 bytes is an .rodata address, is not updated when a new segment is added.

To Reproduce
I do not have a simple input binary that demonstrates this issue, but :

  1. parse AIS-Lite from https://github.com/trailofbits/cb-multios, compiled with gcc (CC=gcc CXX=g++ build.sh)
  2. add new segment to ./AIS-Lite and generate output binary ./added_seg.bin => contents of ./added_seg.bin have mostly been shifted by 0x1000
  3. crudely evaluating the last 8 bytes of contents from each the .data section:
>>>x=lief.parse("./AIS-Lite")
>>>y=lief.parse("./added_seg.bin")
>>>lx=len(x.get_section(".data").content)
>>>ly=len(y.get_section(".data").content)
>>>print(x.get_section(".data").content[lx-8:])
[43, 65, 0, 0, 52, 65, 0, 0]
>>>print(z.get_section(".data").content[lz-8:])
[43, 81, 0, 0, 52, 65, 0, 0]

These addresses correspond to the .rodata offsets 0x41b2 and 0x4134 in the original binary.
In the ./added_seg.bin, the corresponding .rodata offsets for these symbols are 0x51b2 and 0x5134, but in the actual .data contents of ./added_seg.bin are 0x51b2 and 0x4134, respectively. Symbols are fine, just the last .data content has not been updated to the new offset.
I'm not sure if this information is relevant, but the problematic global symbol is a const array of char*.

Expected behavior
I'm expecting that if some .data content is updated to the new offset, then all content is updated.
That means this:

>>>print(z.get_section(".data").content[lz-8:])
[43, 81, 0, 0, 52, 65, 0, 0]

should be:

>>>print(z.get_section(".data").content[lz-8:])
[43, 81, 0, 0, 52, **81**, 0, 0]

Environment (please complete the following information):

  • Ubuntu 19.04
  • Target format: ELF
  • LIEF commit version: 0.10.1-bfe5415

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions