1## These test checks that llvm-objdump will not crash with malformed archive 2## files. The check line is not all that important but the bug fixes to 3## make sure llvm-objdump is robust is what matters. 4 5## Check we report an error when unable to read the size field on an archive as an integer. 6## Check two cases: a) the first member is valid, but the second is not, and b) both are invalid. 7 8# RUN: yaml2obj --docnum=1 -DFIRST="Size: '1%'" %s -o %t.libbogus1a.a 9# RUN: not llvm-objdump --macho --archive-headers %t.libbogus1a.a 2>&1 | \ 10# RUN: FileCheck -check-prefix=BOGUS1 -DVAL='1%' -DOFFSET=8 -DFILE=%t.libbogus1a.a %s 11 12# RUN: yaml2obj --docnum=1 %s -o %t.libbogus1b.a 13# RUN: not llvm-objdump --macho --archive-headers %t.libbogus1b.a 2>&1 | \ 14# RUN: FileCheck -check-prefix=BOGUS1 -DVAL=10% -DOFFSET=68 -DFILE=%t.libbogus1b.a %s 15 16# BOGUS1: '[[FILE]]': truncated or malformed archive (characters in size field in archive member header are not all decimal numbers: '[[VAL]]' for the archive member header at offset [[OFFSET]]) 17 18--- !Arch 19Members: 20 - [[FIRST={}]] 21 - Size: '10%' 22 23## Check we report an error when an archive is truncated and are unable to skip the data of a member and read the next one. 24 25# RUN: yaml2obj --docnum=2 %s -o %t.libbogus2.a 26# RUN: not llvm-objdump --macho --archive-headers %t.libbogus2.a 2>&1 | \ 27# RUN: FileCheck -check-prefix=BOGUS2 -DFILE=%t.libbogus2.a %s 28 29# BOGUS2: '[[FILE]]': truncated or malformed archive (offset to next archive member past the end of the archive after member foo.c) 30 31--- !Arch 32Members: 33 - Name: 'foo.c' 34 Size: '1' 35 36## Check we report an error when we are unable to read the header of a truncated member (but still are able to read its name). 37 38# RUN: yaml2obj --docnum=3 %s -o %t.libbogus3.a 39# RUN: not llvm-objdump --macho --archive-headers %t.libbogus3.a 2>&1 | \ 40# RUN: FileCheck -check-prefix=BOGUS3 -DFILE=%t.libbogus3.a %s 41 42# BOGUS3: '[[FILE]]': truncated or malformed archive (remaining size of archive too small for next archive member header for foo.c) 43 44--- !Arch 45## A single truncated member header containing only the name field, which can be still be printed. 46Content: "666f6f2e632020202020202020202020" ## "foo.c " 47 48## Check we report an error when the terminator characters of an archive member header are not the correct "`\n" string. 49 50# RUN: yaml2obj --docnum=4 %s -o %t.libbogus4.a 51# RUN: not llvm-objdump --macho --archive-headers %t.libbogus4.a 2>&1 | \ 52# RUN: FileCheck -check-prefix=BOGUS4 -DFILE=%t.libbogus4.a %s 53 54# BOGUS4: '[[FILE]]': truncated or malformed archive (terminator characters in archive member "@\n" not the correct "`\n" values for the archive member header for hello.c) 55 56--- !Arch 57Members: 58 - Name: 'hello.c/' 59 Terminator: "@\n" 60 61## Document we report an error when parsing a BSD archive and the name of a member contains a leading space. 62 63# RUN: yaml2obj --docnum=5 %s -o %t.libbogus5.a 64# RUN: not llvm-objdump --macho --archive-headers %t.libbogus5.a 2>&1 | \ 65# RUN: FileCheck -check-prefix=BOGUS5 -DFILE=%t.libbogus5.a %s 66 67# BOGUS5: '[[FILE]]': truncated or malformed archive (name contains a leading space for archive member header at offset 68) 68 69--- !Arch 70Members: 71 - Name: '#1/0' ## Triggers parsing as BFD archive. 72 - Name: ' ' 73 74## Check we report an error when a member's long name length characters after 75## the "#1/" are not all decimal numbers. 76 77# RUN: yaml2obj --docnum=6 %s -o %t.libbogus6.a 78# RUN: not llvm-objdump --macho --archive-headers %t.libbogus6.a 2>&1 | \ 79# RUN: FileCheck -check-prefix=BOGUS6 -DFILE=%t.libbogus6.a %s 80 81# BOGUS6: '[[FILE]]': truncated or malformed archive (long name length characters after the #1/ are not all decimal numbers: '@123$' for archive member header at offset 8) 82 83--- !Arch 84Members: 85 - Name: '#1/@123$' 86 87## Check we report an error when a member's long name length characters extend past the end of the archive. 88 89# RUN: yaml2obj --docnum=7 %s -o %t.libbogus7.a 90# RUN: not llvm-objdump --macho --archive-headers %t.libbogus7.a 2>&1 | \ 91# RUN: FileCheck -check-prefix=BOGUS7 -DFILE=%t.libbogus7.a %s 92 93# BOGUS7: '[[FILE]]': truncated or malformed archive (long name length: 1 extends past the end of the member or archive for archive member header at offset 8) 94 95--- !Arch 96Members: 97 - Name: '#1/1' 98 99## Check we report an error when members long name length characters after 100## the "/" are not all decimal numbers. 101 102# RUN: yaml2obj --docnum=8 %s -o %t.libbogus8.a 103# RUN: not llvm-objdump -s %t.libbogus8.a 2>&1 | FileCheck -check-prefix=BOGUS8 -DFILE=%t.libbogus8.a %s 104 105# BOGUS8: [[FILE]](<file index: 1>): truncated or malformed archive (long name offset characters after the '/' are not all decimal numbers: '&a25*' for archive member header at offset 68) 106 107--- !Arch 108Members: 109## We need the first member to be a valid member to trigger the right error to be reported. 110 - Name: 'hello.c/' 111 - Name: "/&a25*" 112 113## Check we report an error when the long name offset goes past the end of the string table. 114 115# RUN: yaml2obj --docnum=9 %s -o %t.libbogus9.a 116# RUN: not llvm-objdump -s %t.libbogus9.a 2>&1 | FileCheck -check-prefix=BOGUS9 -DFILE=%t.libbogus9.a %s 117 118# BOGUS9: [[FILE]](<file index: 0>): truncated or malformed archive (long name offset 1 past the end of the string table for archive member header at offset 68) 119 120--- !Arch 121Members: 122 - Name: '//' ## String table. 123 - Name: '/1' 124 125## Check we report an error when the characters in the UID field of a member header are not all decimal numbers. 126 127# RUN: yaml2obj --docnum=10 %s -o %t.libbogus10.a 128# RUN: not llvm-objdump --macho --archive-headers \ 129# RUN: %t.libbogus10.a 2>&1 | FileCheck -check-prefix=BOGUS10 -DFILE=%t.libbogus10.a %s 130 131# BOGUS10: [[FILE]](hello.c): truncated or malformed archive (characters in UID field in archive member header are not all decimal numbers: '~97&' for the archive member header at offset 8) 132 133--- !Arch 134Members: 135 - Name: hello.c 136 UID: '~97&' 137 138## Check we report an error when the characters in the GID field of a member header are not all decimal numbers. 139 140# RUN: yaml2obj --docnum=11 %s -o %t.libbogus11.a 141# RUN: not llvm-objdump --macho --archive-headers \ 142# RUN: %t.libbogus11.a 2>&1 | FileCheck -check-prefix=BOGUS11 -DFILE=%t.libbogus11.a %s 143 144# BOGUS11: [[FILE]](hello.c): truncated or malformed archive (characters in GID field in archive member header are not all decimal numbers: '#55!' for the archive member header at offset 8) 145 146--- !Arch 147Members: 148 - Name: hello.c 149 GID: '#55!' 150 151## Check we report an error when the characters in the AccessMode field of a member header are not all octal numbers. 152 153# RUN: yaml2obj --docnum=12 %s -o %t.libbogus12.a 154# RUN: not llvm-objdump --macho --archive-headers \ 155# RUN: %t.libbogus12.a 2>&1 | FileCheck -check-prefix=BOGUS12 -DFILE=%t.libbogus12.a %s 156 157# BOGUS12: [[FILE]](hello.c): truncated or malformed archive (characters in AccessMode field in archive member header are not all octal numbers: 'Feed' for the archive member header at offset 8) 158 159--- !Arch 160Members: 161 - Name: hello.c 162 AccessMode: 'Feed' 163 164## Check we report an error when the characters in the LastModified field of a member header are not all decimal numbers. 165 166# RUN: yaml2obj --docnum=13 %s -o %t.libbogus13.a 167# RUN: llvm-objdump --macho --archive-headers %t.libbogus13.a 2>&1 | \ 168# RUN: FileCheck -check-prefix=BOGUS13A %s 169 170# BOGUS13A: ---------- 0/0 0 (date: "1foobar273" contains non-decimal chars) hello.c 171 172--- !Arch 173Members: 174 - Name: hello.c 175 LastModified: '1foobar273' 176 177# RUN: not llvm-ar tv %t.libbogus13.a 2>&1 | \ 178# RUN: FileCheck -check-prefix=BOGUS13B %s 179 180# BOGUS13B: error: truncated or malformed archive (characters in LastModified field in archive member header are not all decimal numbers: '1foobar273' for the archive member header at offset 8) 181 182## TODO: add testing for AIX Big archive. 183