Skip to content

Commit 8c5e573

Browse files
committed
avoid-uaf
1 parent 921185b commit 8c5e573

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

toolchain/check/impl_lookup.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static auto FindAndDiagnoseImplLookupCycle(
184184
}
185185

186186
struct InterfacesFromConstantId {
187-
llvm::ArrayRef<SemIR::SpecificInterface> interfaces;
187+
llvm::SmallVector<SemIR::SpecificInterface> interfaces;
188188
SemIR::BuiltinConstraintMask builtin_constraint_mask;
189189
bool other_requirements;
190190
};
@@ -211,9 +211,14 @@ static auto GetInterfacesFromConstantId(
211211
if (!identified_id.has_value()) {
212212
return std::nullopt;
213213
}
214-
return {{.interfaces = context.identified_facet_types()
215-
.Get(identified_id)
216-
.required_interfaces(),
214+
// TODO: IdentifiedFacetTypes are held in a RelationalValueStore which does
215+
// not protect against UAF through reallocation, so we must copy data out of
216+
// it.
217+
llvm::SmallVector<SemIR::SpecificInterface> interfaces(
218+
context.identified_facet_types()
219+
.Get(identified_id)
220+
.required_interfaces());
221+
return {{.interfaces = std::move(interfaces),
217222
.builtin_constraint_mask = facet_type_info.builtin_constraint_mask,
218223
.other_requirements = facet_type_info.other_requirements}};
219224
}

0 commit comments

Comments
 (0)