Skip to content

Commit 20048bd

Browse files
committed
Runtime: Bounds check method override descriptors
1 parent fa2ab3b commit 20048bd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,11 +2383,20 @@ static void initClassVTable(ClassMetadata *self) {
23832383
// Calculate the base method's vtable offset from the
23842384
// base method descriptor. The offset will be relative
23852385
// to the base class's vtable start offset.
2386-
auto baseClassMethods = baseClass->getMethodDescriptors().data();
2387-
auto offset = baseMethod - baseClassMethods;
2386+
auto baseClassMethods = baseClass->getMethodDescriptors();
2387+
2388+
// If the method descriptor doesn't land within the bounds of the
2389+
// method table, abort.
2390+
if (baseMethod < baseClassMethods.begin() ||
2391+
baseMethod >= baseClassMethods.end()) {
2392+
fatalError(0, "resilient vtable at %p contains out-of-bounds "
2393+
"method descriptor %p\n",
2394+
overrideTable, baseMethod);
2395+
}
23882396

23892397
// Install the method override in our vtable.
23902398
auto baseVTable = baseClass->getVTableDescriptor();
2399+
auto offset = baseMethod - baseClassMethods.data();
23912400
classWords[baseVTable->getVTableOffset(baseClass) + offset]
23922401
= descriptor.Impl.get();
23932402
}

0 commit comments

Comments
 (0)