Skip to content

Commit

Permalink
Validate the pointer when receiving from object
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jul 12, 2024
1 parent 4e9761d commit f3bec2b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/prototype.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ struct Type<T*, std::enable_if_t<!std::is_const_v<T> &&
void* result;
if (napi_unwrap(env, value, &result) != napi_ok)
return std::nullopt;
if (internal::CanCachePointer<T>::value) {
// Check if the pointer has been released by user.
napi_value obj;
if (!InstanceData::Get(env)->GetWeakRef<T>(result, &obj))
return std::nullopt;
}
if (!internal::IsInstanceOf<T>(env, value))
return std::nullopt;
T* ptr = internal::Unwrap<T>::Do(result);
Expand Down

0 comments on commit f3bec2b

Please sign in to comment.