summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Support/YAMLTraits.h3
-rw-r--r--llvm/test/tools/obj2yaml/invalid-section-name.yaml31
2 files changed, 33 insertions, 1 deletions
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index 656020ec49d..a3bfa7dc467 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -649,7 +649,8 @@ inline bool isBool(StringRef S) {
inline QuotingType needsQuotes(StringRef S) {
if (S.empty())
return QuotingType::Single;
- if (isspace(S.front()) || isspace(S.back()))
+ if (isspace(static_cast<unsigned char>(S.front())) ||
+ isspace(static_cast<unsigned char>(S.back())))
return QuotingType::Single;
if (isNull(S))
return QuotingType::Single;
diff --git a/llvm/test/tools/obj2yaml/invalid-section-name.yaml b/llvm/test/tools/obj2yaml/invalid-section-name.yaml
new file mode 100644
index 00000000000..ed972ef75ca
--- /dev/null
+++ b/llvm/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"
OpenPOWER on IntegriCloud