[PATCH] D37331: [ELF] Prevent crash with binary inputs with non-ascii file names
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 01:31:37 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312705: [ELF] Prevent crash with binary inputs with non-ascii file names (authored by jhenderson).
Changed prior to commit:
https://reviews.llvm.org/D37331?vs=114001&id=114127#toc
Repository:
rL LLVM
https://reviews.llvm.org/D37331
Files:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/Strings.cpp
lld/trunk/ELF/Strings.h
lld/trunk/test/ELF/format-binary-non-ascii.s
Index: lld/trunk/test/ELF/format-binary-non-ascii.s
===================================================================
--- lld/trunk/test/ELF/format-binary-non-ascii.s
+++ lld/trunk/test/ELF/format-binary-non-ascii.s
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t£.o
+
+# RUN: ld.lld -o %t.elf %t£.o --format=binary %t£.o
+# RUN: llvm-readobj -symbols %t.elf | FileCheck %s
+
+# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp___o_start
+# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp___o_end
+# CHECK: Name: _binary_{{[a-zA-Z0-9_]+}}test_ELF_Output_format_binary_non_ascii_s_tmp___o_size
+
+.text
+.align 4
+.globl _start
+_start:
+ nop
Index: lld/trunk/ELF/Strings.cpp
===================================================================
--- lld/trunk/ELF/Strings.cpp
+++ lld/trunk/ELF/Strings.cpp
@@ -58,7 +58,9 @@
return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z') || C == '_';
}
-static bool isAlnum(char C) { return isAlpha(C) || ('0' <= C && C <= '9'); }
+// Returns true if C is a valid letter, digit or underscore as defined in the
+// "C" locale.
+bool elf::isAlnum(char C) { return isAlpha(C) || ('0' <= C && C <= '9'); }
// Returns true if S is valid as a C language identifier.
bool elf::isValidCIdentifier(StringRef S) {
Index: lld/trunk/ELF/InputFiles.cpp
===================================================================
--- lld/trunk/ELF/InputFiles.cpp
+++ lld/trunk/ELF/InputFiles.cpp
@@ -931,7 +931,7 @@
// characters in a filename are replaced with underscore.
std::string S = "_binary_" + MB.getBufferIdentifier().str();
for (size_t I = 0; I < S.size(); ++I)
- if (!isalnum(S[I]))
+ if (!elf::isAlnum(S[I]))
S[I] = '_';
Symtab->addRegular<ELFT>(Saver.save(S + "_start"), STV_DEFAULT, STT_OBJECT,
Index: lld/trunk/ELF/Strings.h
===================================================================
--- lld/trunk/ELF/Strings.h
+++ lld/trunk/ELF/Strings.h
@@ -22,6 +22,7 @@
namespace elf {
std::vector<uint8_t> parseHex(StringRef S);
+bool isAlnum(char C);
bool isValidCIdentifier(StringRef S);
// This is a lazy version of StringRef. String size is computed lazily
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37331.114127.patch
Type: text/x-patch
Size: 2285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170907/7e3f8995/attachment.bin>
More information about the llvm-commits
mailing list