1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[llvm-objcopy] Fix crash for binary input files with non-ascii names

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 provoke undefined behaviour, which can in some
cases result in crashes.

Reviewed by: MaskRay

Differential Revision: https://reviews.llvm.org/D97663
This commit is contained in:
James Henderson 2021-02-23 15:32:45 +00:00
parent 7843c09e83
commit 6d55f9cfe4
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -1290,8 +1290,9 @@ void BinaryELFBuilder::addData(SymbolTableSection *SymTab) {
DataSection.Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE;
std::string SanitizedFilename = MemBuf->getBufferIdentifier().str();
std::replace_if(std::begin(SanitizedFilename), std::end(SanitizedFilename),
[](char C) { return !isalnum(C); }, '_');
std::replace_if(
std::begin(SanitizedFilename), std::end(SanitizedFilename),
[](char C) { return !isAlnum(C); }, '_');
Twine Prefix = Twine("_binary_") + SanitizedFilename;
SymTab->addSymbol(Prefix + "_start", STB_GLOBAL, STT_NOTYPE, &DataSection,