[PATCH] D69160: [obj2yaml] - Stop triggering UB when dumping corrupted strings.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 03:40:13 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ec0b0843896: [obj2yaml] - Stop triggering UB when dumping corrupted strings. (authored by grimar).
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D69160?vs=225573&id=225849#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69160/new/

https://reviews.llvm.org/D69160

Files:
  llvm/include/llvm/Support/YAMLTraits.h
  llvm/test/tools/obj2yaml/invalid-section-name.yaml


Index: llvm/test/tools/obj2yaml/invalid-section-name.yaml
===================================================================
--- /dev/null
+++ 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"
Index: llvm/include/llvm/Support/YAMLTraits.h
===================================================================
--- llvm/include/llvm/Support/YAMLTraits.h
+++ llvm/include/llvm/Support/YAMLTraits.h
@@ -649,7 +649,8 @@
 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69160.225849.patch
Type: text/x-patch
Size: 1671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191021/91770011/attachment.bin>


More information about the llvm-commits mailing list