llvm.org GIT mirror llvm / ebd8336
Think this will fix issues with the error messages generated for malformed-archives.test in r277177 and added back this test which was deleted in r277196 while I tracked down these problems. Changed from constructing Twine's to std::string's as Twine's don't work across statements. Also removed a few unneeded Twine() constructions. Fix the write_escaped() calls to not pass the unintended second argument fixing the warning on the ld-x86_64-win7 bot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277223 91177308-0d34-0410-b5e6-96231b3b80d8 Kevin Enderby 3 years ago
2 changed file(s) with 73 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
4444
4545 if (Size < sizeof(ArMemHdrType)) {
4646 if (Err) {
47 Twine Msg("remaining size of archive too small for next archive member "
48 "header ");
47 std::string Msg("remaining size of archive too small for next archive "
48 "member header ");
4949 Expected NameOrErr = getName(Size);
5050 if (!NameOrErr) {
5151 consumeError(NameOrErr.takeError());
5252 uint64_t Offset = RawHeaderPtr - Parent->getData().data();
5353 *Err = malformedError(Msg + "at offset " + Twine(Offset));
5454 } else
55 *Err = malformedError(Msg + "for " + Twine(NameOrErr.get()));
55 *Err = malformedError(Msg + "for " + NameOrErr.get());
5656 }
5757 return;
5858 }
6363 OS.write_escaped(llvm::StringRef(ArMemHdr->Terminator,
6464 sizeof(ArMemHdr->Terminator)));
6565 OS.flush();
66 Twine Msg("terminator characters in archive member \"" + Buf + "\" not "
67 "the correct \"`\\n\" values for the archive member header ");
66 std::string Msg("terminator characters in archive member \"" + Buf +
67 "\" not the correct \"`\\n\" values for the archive "
68 "member header ");
6869 Expected NameOrErr = getName(Size);
6970 if (!NameOrErr) {
7071 consumeError(NameOrErr.takeError());
7172 uint64_t Offset = RawHeaderPtr - Parent->getData().data();
7273 *Err = malformedError(Msg + "at offset " + Twine(Offset));
7374 } else
74 *Err = malformedError(Msg + "for " + Twine(NameOrErr.get()));
75 *Err = malformedError(Msg + "for " + NameOrErr.get());
7576 }
7677 return;
7778 }
138139 if (Name.substr(1).rtrim(' ').getAsInteger(10, StringOffset)) {
139140 std::string Buf;
140141 raw_string_ostream OS(Buf);
141 OS.write_escaped(Name.substr(1).rtrim(' '),
142 sizeof(Name.substr(1)).rtrim(' '));
142 OS.write_escaped(Name.substr(1).rtrim(' '));
143143 OS.flush();
144144 uint64_t ArchiveOffset = reinterpret_cast(ArMemHdr) -
145145 Parent->getData().data();
171171 if (Name.substr(3).rtrim(' ').getAsInteger(10, NameLength)) {
172172 std::string Buf;
173173 raw_string_ostream OS(Buf);
174 OS.write_escaped(Name.substr(3).rtrim(' '),
175 sizeof(Name.substr(3)).rtrim(' '));
174 OS.write_escaped(Name.substr(3).rtrim(' '));
176175 OS.flush();
177176 uint64_t ArchiveOffset = reinterpret_cast(ArMemHdr) -
178177 Parent->getData().data();
315314 if (Err) {
316315 std::string Buf;
317316 raw_string_ostream OS(Buf);
318 OS.write_escaped(Name.substr(3).rtrim(' '),
319 sizeof(Name.substr(3)).rtrim(' '));
317 OS.write_escaped(Name.substr(3).rtrim(' '));
320318 OS.flush();
321319 uint64_t Offset = Start - Parent->getData().data();
322320 *Err = malformedError("long name length characters after the #1/ are "
406404
407405 // Check to see if this is past the end of the archive.
408406 if (NextLoc > Parent->Data.getBufferEnd()) {
409 Twine Msg("offset to next archive member past the end of the archive after "
410 "member ");
407 std::string Msg("offset to next archive member past the end of the archive "
408 "after member ");
411409 Expected NameOrErr = getName();
412410 if (!NameOrErr) {
413411 consumeError(NameOrErr.takeError());
414412 uint64_t Offset = Data.data() - Parent->getData().data();
415413 return malformedError(Msg + "at offset " + Twine(Offset));
416414 } else
417 return malformedError(Msg + Twine(NameOrErr.get()));
415 return malformedError(Msg + NameOrErr.get());
418416 }
419417
420418 Error Err;
0 // These test checks that llvm-objdump will not crash with malformed Archive
1 // files. So the check line is not all that important but the bug fixes to
2 // make sure llvm-objdump is robust is what matters.
3 # RUN: not llvm-objdump -macho -archive-headers \
4 # RUN: %p/Inputs/libbogus1.a \
5 # RUN: 2>&1 | FileCheck -check-prefix=bogus1 %s
6
7 # bogus1: libbogus1.a': truncated or malformed archive (characters in size field in archive header are not all decimal numbers: '10%' for archive member header at offset 8)
8
9 # RUN: not llvm-objdump -macho -archive-headers \
10 # RUN: %p/Inputs/libbogus2.a \
11 # RUN: 2>&1 | FileCheck -check-prefix=bogus2 %s
12
13 # bogus2: libbogus2.a': truncated or malformed archive (characters in size field in archive header are not all decimal numbers: '1%' for archive member header at offset 170)
14
15 # RUN: not llvm-objdump -macho -archive-headers \
16 # RUN: %p/Inputs/libbogus3.a \
17 # RUN: 2>&1 | FileCheck -check-prefix=bogus3 %s
18
19 # bogus3: libbogus3.a': truncated or malformed archive (offset to next archive member past the end of the archive after member foo.c)
20
21 # RUN: not llvm-objdump -macho -archive-headers \
22 # RUN: %p/Inputs/libbogus4.a \
23 # RUN: 2>&1 | FileCheck -check-prefix=bogus4 %s
24
25 # bogus4: libbogus4.a': truncated or malformed archive (remaining size of archive too small for next archive member header for foo.c)
26
27 # RUN: not llvm-objdump -macho -archive-headers \
28 # RUN: %p/Inputs/libbogus5.a \
29 # RUN: 2>&1 | FileCheck -check-prefix=bogus5 %s
30
31 # bogus5: libbogus5.a': truncated or malformed archive (terminator characters in archive member "@\n" not the correct "`\n" values for the archive member header for hello.c)
32
33 # RUN: not llvm-objdump -macho -archive-headers \
34 # RUN: %p/Inputs/libbogus6.a \
35 # RUN: 2>&1 | FileCheck -check-prefix=bogus6 %s
36
37 # bogus6: libbogus6.a': truncated or malformed archive (name contains a leading space for archive member header at offset 96)
38
39 # RUN: not llvm-objdump -macho -archive-headers \
40 # RUN: %p/Inputs/libbogus7.a \
41 # RUN: 2>&1 | FileCheck -check-prefix=bogus7 %s
42
43 # bogus7: libbogus7.a': truncated or malformed archive (long name length characters after the #1/ are not all decimal numbers: '@123$' for archive member header at offset 8)
44
45 # RUN: not llvm-objdump -macho -archive-headers \
46 # RUN: %p/Inputs/libbogus8.a \
47 # RUN: 2>&1 | FileCheck -check-prefix=bogus8 %s
48
49 # bogus8: libbogus8.a(???) truncated or malformed archive (long name length: 1234 extends past the end of the member or archive for archive member header at offset 86)
50
51 # RUN: not llvm-objdump -s %p/Inputs/libbogus9.a \
52 # RUN: 2>&1 | FileCheck -check-prefix=bogus9 %s
53
54 # bogus9: libbogus9.a(???) truncated or malformed archive (long name offset characters after the '/' are not all decimal numbers: '&a25*' for archive member header at offset 94)
55
56 # RUN: not llvm-objdump -s %p/Inputs/libbogus10.a \
57 # RUN: 2>&1 | FileCheck -check-prefix=bogus10 %s
58
59 # bogus10: libbogus10.a(???) truncated or malformed archive (long name offset 507 past the end of the string table for archive member header at offset 94)