Skip to content

Commit

Permalink
MiraclePtr: Avoid storing ExtractAsDangling() into a variable.
Browse files Browse the repository at this point in the history
ExtractAsDangling() converts the raw_ptr into a raw_ptr allowed to
dangle. This is expected to be used immediately as a temporary object,
and not stored as a naked pointer.

This relies on C++ calling destructor of temporaries at the end of the
full expression. It means MiraclePtr will continue to consider the
object "referenced" during the expression and continue to protect
against UAF during the callback call.

Bug: None
Change-Id: If9436fb9626253b24c51d2c1db1701d22513fcd3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/206274
Auto-Submit: Arthur Sonzogni <[email protected]>
Commit-Queue: Arthur Sonzogni <[email protected]>
Reviewed-by: Corentin Wallez <[email protected]>
Commit-Queue: Corentin Wallez <[email protected]>
  • Loading branch information
ArthurSonzogni authored and Dawn LUCI CQ committed Sep 11, 2024
1 parent b26fd0e commit b0dd53c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/dawn/wire/client/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ class PopErrorScopeEvent final : public TrackedEvent {
mStatus = WGPUPopErrorScopeStatus_InstanceDropped;
mMessage = std::nullopt;
}
void* userdata1 = mUserdata1.ExtractAsDangling();
void* userdata2 = mUserdata2.ExtractAsDangling();
if (mCallback) {
mCallback(mStatus, mType, mMessage ? mMessage->c_str() : nullptr, userdata1, userdata2);
mCallback(mStatus, mType, mMessage ? mMessage->c_str() : nullptr,
mUserdata1.ExtractAsDangling(), mUserdata2.ExtractAsDangling());
}
}

Expand Down

0 comments on commit b0dd53c

Please sign in to comment.