Skip to content

Commit db78ee0

Browse files
authored
[lld-macho] Fix address sanitizer for category merging (#91680)
FIxing the address sanitizer issue reported in #91548 . The problem comes from the assignment `auto bodyData = newSectionData` which defaults to `SmallVector<uint8_t> data = newSectionData` - which actually creates a copy of the data, placed on the stack. By explicitly using `ArrayRef` instead, we make sure that the original copy is used. We also change the assignment in `ObjcCategoryMerger::newStringData` from `auto` to `SmallVector<uint8_t> &` to make it explicit.
1 parent 0fd017c commit db78ee0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lld/MachO/ObjC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ void ObjcCategoryMerger::generateCatListForNonErasedCategories(
11481148
assert(nonErasedCatBody && "Failed to relocate non-deleted category");
11491149

11501150
// Allocate data for the new __objc_catlist slot
1151-
auto bodyData = newSectionData(target->wordSize);
1151+
llvm::ArrayRef<uint8_t> bodyData = newSectionData(target->wordSize);
11521152

11531153
// We mark the __objc_catlist slot as belonging to the same file as the
11541154
// category
@@ -1279,7 +1279,7 @@ void ObjcCategoryMerger::doCleanup() { generatedSectionData.clear(); }
12791279
StringRef ObjcCategoryMerger::newStringData(const char *str) {
12801280
uint32_t len = strlen(str);
12811281
uint32_t bufSize = len + 1;
1282-
auto &data = newSectionData(bufSize);
1282+
SmallVector<uint8_t> &data = newSectionData(bufSize);
12831283
char *strData = reinterpret_cast<char *>(data.data());
12841284
// Copy the string chars and null-terminator
12851285
memcpy(strData, str, bufSize);

0 commit comments

Comments
 (0)