Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
MachO: Fix out-of-bounds memory access in getString16
Browse files Browse the repository at this point in the history
Summary:
This fixes the following tests when gcc is compiled with gcc8:

lld :: mach-o/do-not-emit-unwind-fde-arm64.yaml
lld :: mach-o/eh-frame-relocs-arm64.yaml

llvm.org/PR38096

Reviewers: lhames, kledzik, javed.absar

Subscribers: kristof.beyls, llvm-commits

Differential Revision: https://reviews.llvm.org/D51547

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@341670 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tstellar committed Sep 7, 2018
1 parent ca0c8ca commit c0aa57c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h
Expand Up @@ -185,12 +185,11 @@ packRelocation(const Relocation &r, bool swap, bool isBigEndian) {
return result;
}

inline StringRef getString16(const char s[16]) {
StringRef x = s;
if ( x.size() > 16 )
return x.substr(0, 16);
else
return x;
static StringRef getString16(const char s[16]) {
// The StringRef(const char *) constructor passes the const char * to
// strlen(), so we can't use this constructor here, because if there is no
// null terminator in s, then strlen() will read past the end of the array.
return StringRef(s, strnlen(s, 16));
}

inline void setString16(StringRef str, char s[16]) {
Expand Down

0 comments on commit c0aa57c

Please sign in to comment.