[PATCH] D97663: [llvm-objcopy] Fix crash for binary input files with non-ascii names
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 1 01:09:52 PST 2021
jhenderson created this revision.
jhenderson added reviewers: MaskRay, grimar, rupprecht, alexshap.
Herald added subscribers: abrachet, emaste.
jhenderson requested review of this revision.
Herald added a project: LLVM.
The code was using the standard isalnum function which doesn't handle values outside the non-ascii range. Switching to using llvm::isAlnum instead ensures we don't crash.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97663
Files:
llvm/test/tools/llvm-objcopy/ELF/binary-input.test
llvm/tools/llvm-objcopy/ELF/Object.cpp
Index: llvm/tools/llvm-objcopy/ELF/Object.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -1291,7 +1291,7 @@
std::string SanitizedFilename = MemBuf->getBufferIdentifier().str();
std::replace_if(std::begin(SanitizedFilename), std::end(SanitizedFilename),
- [](char C) { return !isalnum(C); }, '_');
+ [](char C) { return !isAlnum(C); }, '_');
Twine Prefix = Twine("_binary_") + SanitizedFilename;
SymTab->addSymbol(Prefix + "_start", STB_GLOBAL, STT_NOTYPE, &DataSection,
Index: llvm/test/tools/llvm-objcopy/ELF/binary-input.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/binary-input.test
+++ llvm/test/tools/llvm-objcopy/ELF/binary-input.test
@@ -118,3 +118,10 @@
# ALIGN: Name: .data
# ALIGN: AddressAlignment:
# ALIGN-SAME: 8{{$}}
+
+## Show that a filename with non-ASCII characters can be handled appropriately.
+## The exact encoding of the non-ASCII character will determine what characters
+## are used, so don't check for them specifically.
+# RUN: cp %t.x-txt %t€.x-txt
+# RUN: llvm-objcopy -I binary -O elf64-x86-64 %t€.x-txt %t3.o
+# RUN: llvm-readobj --sections --symbols %t3.o | FileCheck %s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97663.327044.patch
Type: text/x-patch
Size: 1367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210301/bca6f398/attachment.bin>
More information about the llvm-commits
mailing list