File: elf-malformed-pt-dynamic.test

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,436 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (47 lines) | stat: -rw-r--r-- 1,541 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# If the offset and/or size fields of the PT_DYNAMIC field become corrupted,
# we should report a sensible error message.

# Creating such a malformed file is hard. The easiest way to simulate it is to
# truncate the file. Note that the section headers must first be stripped or
# llvm-readobj will fail to parse the file due to the section header table
# offset pointing outside the file.

# RUN: yaml2obj %s -o %t.base
# RUN: llvm-objcopy --strip-sections %t.base %t.stripped

# Test case where the size is too large to fit in the file, but the start is
# within the file.
# RUN: cp %t.stripped %t.truncated1
# RUN: %python -c "with open(r'%t.truncated1', 'r+') as f: f.truncate(0x1001)"
# RUN: not llvm-readobj %t.truncated1 --dynamic-table 2>&1 | FileCheck %s

# Test case where the offset is too large to be in the file.
# RUN: cp %t.stripped %t.truncated2
# RUN: %python -c "with open(r'%t.truncated2', 'r+') as f: f.truncate(0xFFF)"
# RUN: not llvm-readobj %t.truncated2 --dynamic-table 2>&1 | FileCheck %s

# CHECK: error: PT_DYNAMIC segment offset + size exceeds the size of the file

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:         .dynamic
    Type:         SHT_DYNAMIC
    Address:      0x1000
    AddressAlign: 0x1000
    Entries:
      - Tag:   DT_NULL
        Value: 0
ProgramHeaders:
  - Type: PT_LOAD
    VAddr: 0x1000
    Sections:
      - Section: .dynamic
  - Type: PT_DYNAMIC
    VAddr: 0x1000
    Sections:
      - Section: .dynamic