[PATCH] D39458: Do not access beyond the end of local symbols.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 31 10:01:57 PDT 2017
ruiu created this revision.
This patch resurrects code that was removed in r317007 to not access
beyond allocated memory for a symbol.
https://reviews.llvm.org/D39458
Files:
lld/COFF/SymbolTable.cpp
Index: lld/COFF/SymbolTable.cpp
===================================================================
--- lld/COFF/SymbolTable.cpp
+++ lld/COFF/SymbolTable.cpp
@@ -106,7 +106,17 @@
// A weak alias may have been resolved, so check for that.
if (Defined *D = Undef->getWeakAlias()) {
- memcpy(Sym, D, sizeof(SymbolUnion));
+ // We want to replace Sym with D. However, we can't just blindly
+ // copy sizeof(SymbolUnion) bytes from D to Sym because D may be an
+ // internal symbol, and internal symbols are stored as "unparented"
+ // Symbols. For that reason we need to check which type of symbol we
+ // are dealing with and copy the correct number of bytes.
+ if (isa<DefinedRegular>(D))
+ memcpy(Sym, D, sizeof(DefinedRegular));
+ else if (isa<DefinedAbsolute>(D))
+ memcpy(Sym, D, sizeof(DefinedAbsolute));
+ else
+ memcpy(Sym, D, sizeof(SymbolUnion));
continue;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39458.121006.patch
Type: text/x-patch
Size: 958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171031/0b2e05d4/attachment.bin>
More information about the llvm-commits
mailing list