diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-09-10 07:55:48 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-09-10 07:55:48 +0000 |
commit | f3a22c30718571fef6b0e55d8fd5ac0805215d73 (patch) | |
tree | f62d340e9455139b5b4f63936616a5e1664b55d8 | |
parent | cef4d2564de991c58e86a6d1979e2742b36dfcd6 (diff) |
Merging r341670 and r341672:
------------------------------------------------------------------------
r341670 | tstellar | 2018-09-07 17:42:01 +0200 (Fri, 07 Sep 2018) | 15 lines
MachO: Fix out-of-bounds memory access in getString16
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
------------------------------------------------------------------------
------------------------------------------------------------------------
r341672 | tstellar | 2018-09-07 17:51:52 +0200 (Fri, 07 Sep 2018) | 3 lines
MachO: Change getString16() back to inline function
This was accidentally changed in r341670.
------------------------------------------------------------------------
-rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h index 407bd9b9702..ee9e174b82e 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryUtils.h @@ -186,11 +186,10 @@ packRelocation(const Relocation &r, bool swap, bool isBigEndian) { } inline StringRef getString16(const char s[16]) { - StringRef x = s; - if ( x.size() > 16 ) - return x.substr(0, 16); - else - return x; + // 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]) { |