diff options
author | George Rimar <grimar@accesssoftek.com> | 2019-10-21 10:38:03 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2019-10-21 10:38:03 +0000 |
commit | 63b9649758d269176eda84f153cec6738d2edc4a (patch) | |
tree | bf9057e378216e7ef5eef75227a5c2f65e199c54 /test | |
parent | 7fc698b06acd483d3ad8ee5a64703fd67e021b1c (diff) |
[obj2yaml] - Stop triggering UB when dumping corrupted strings.
We have a following code to find quote type:
if (isspace(S.front()) || isspace(S.back()))
...
Problem is that:
"int isspace( int ch ): The behavior is undefined if the value of
ch is not representable as unsigned char and is not equal to EOF."
(https://en.cppreference.com/w/cpp/string/byte/isspace)
This patch shows how this UB can be triggered and fixes an issue.
Differential revision: https://reviews.llvm.org/D69160
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375404 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/tools/obj2yaml/invalid-section-name.yaml | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/tools/obj2yaml/invalid-section-name.yaml b/test/tools/obj2yaml/invalid-section-name.yaml new file mode 100644 index 00000000000..ed972ef75ca --- /dev/null +++ b/test/tools/obj2yaml/invalid-section-name.yaml @@ -0,0 +1,31 @@ +## Check we do not crash/assert when dumping a broken section name. +## Here we replace "foo" name with a sequence of characters that +## do are not representable as unsigned char. +## We used to have an assert for this case before. + +# RUN: yaml2obj %s -o %t +# RUN: obj2yaml %t | FileCheck %s + +# CHECK: --- !ELF +# CHECK-NEXT: FileHeader: +# CHECK-NEXT: Class: ELFCLASS64 +# CHECK-NEXT: Data: ELFDATA2LSB +# CHECK-NEXT: Type: ET_REL +# CHECK-NEXT: Machine: EM_X86_64 +# CHECK-NEXT: Sections: +# CHECK-NEXT: - Name: "{{.*}}" +# CHECK-NEXT: Type: SHT_PROGBITS +# CHECK-NEXT: ... + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: foo + Type: SHT_PROGBITS + - Name: .shstrtab + Type: SHT_STRTAB + Content: "00FEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFE00" |