Skip to content

Commit e06ace6

Browse files
addaleaxCommit Bot
authored andcommitted
[api] Fix empty Maybe crash in GetRealNamedPropertyAttributes
`Object::GetRealNamedPropertyAttributes()` can crash if an empty `Maybe` is returned by `JSReceiver::GetPropertyAttributes()` because it was not checking for that. Fix that. Refs: nodejs/node#34606 Change-Id: Ic83f904ba7134786bcd8f786eb2ce98adb4fea1e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2335057 Commit-Queue: Leszek Swirski <[email protected]> Reviewed-by: Leszek Swirski <[email protected]> Cr-Commit-Position: refs/heads/master@{#69258}
1 parent 6315167 commit e06ace6

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

src/api/api.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,9 +4728,9 @@ Maybe<PropertyAttribute>
47284728
v8::Object::GetRealNamedPropertyAttributesInPrototypeChain(
47294729
Local<Context> context, Local<Name> key) {
47304730
auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
4731-
ENTER_V8_NO_SCRIPT(isolate, context, Object,
4732-
GetRealNamedPropertyAttributesInPrototypeChain,
4733-
Nothing<PropertyAttribute>(), i::HandleScope);
4731+
ENTER_V8(isolate, context, Object,
4732+
GetRealNamedPropertyAttributesInPrototypeChain,
4733+
Nothing<PropertyAttribute>(), i::HandleScope);
47344734
i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
47354735
if (!self->IsJSObject()) return Nothing<PropertyAttribute>();
47364736
i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
@@ -4743,6 +4743,7 @@ v8::Object::GetRealNamedPropertyAttributesInPrototypeChain(
47434743
i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
47444744
Maybe<i::PropertyAttributes> result =
47454745
i::JSReceiver::GetPropertyAttributes(&it);
4746+
has_pending_exception = result.IsNothing();
47464747
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
47474748
if (!it.IsFound()) return Nothing<PropertyAttribute>();
47484749
if (result.FromJust() == i::ABSENT) return Just(None);
@@ -4767,14 +4768,15 @@ MaybeLocal<Value> v8::Object::GetRealNamedProperty(Local<Context> context,
47674768
Maybe<PropertyAttribute> v8::Object::GetRealNamedPropertyAttributes(
47684769
Local<Context> context, Local<Name> key) {
47694770
auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
4770-
ENTER_V8_NO_SCRIPT(isolate, context, Object, GetRealNamedPropertyAttributes,
4771-
Nothing<PropertyAttribute>(), i::HandleScope);
4771+
ENTER_V8(isolate, context, Object, GetRealNamedPropertyAttributes,
4772+
Nothing<PropertyAttribute>(), i::HandleScope);
47724773
i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
47734774
i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
47744775
i::LookupIterator::Key lookup_key(isolate, key_obj);
47754776
i::LookupIterator it(isolate, self, lookup_key, self,
47764777
i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
47774778
auto result = i::JSReceiver::GetPropertyAttributes(&it);
4779+
has_pending_exception = result.IsNothing();
47784780
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(PropertyAttribute);
47794781
if (!it.IsFound()) return Nothing<PropertyAttribute>();
47804782
if (result.FromJust() == i::ABSENT) {

test/cctest/test-api.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11985,6 +11985,48 @@ THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
1198511985
CHECK(result.IsEmpty());
1198611986
}
1198711987

11988+
THREADED_TEST(GetRealNamedPropertyAttributes_With_Proxy) {
11989+
LocalContext context;
11990+
HandleScope scope(context->GetIsolate());
11991+
11992+
{
11993+
Local<Object> proxy =
11994+
CompileRun(
11995+
"new Proxy({ p: 1 }, { getOwnPropertyDescriptor: _ => { "
11996+
" throw new Error('xyz'); } });")
11997+
.As<Object>();
11998+
TryCatch try_catch(context->GetIsolate());
11999+
v8::Maybe<v8::PropertyAttribute> result =
12000+
proxy->GetRealNamedPropertyAttributes(context.local(), v8_str("p"));
12001+
CHECK(result.IsNothing());
12002+
CHECK(try_catch.HasCaught());
12003+
CHECK(try_catch.Exception()
12004+
.As<Object>()
12005+
->Get(context.local(), v8_str("message"))
12006+
.ToLocalChecked()
12007+
->StrictEquals(v8_str("xyz")));
12008+
}
12009+
12010+
{
12011+
Local<Object> proxy =
12012+
CompileRun(
12013+
"Object.create("
12014+
" new Proxy({ p: 1 }, { getOwnPropertyDescriptor: _ => { "
12015+
" throw new Error('abc'); } }))")
12016+
.As<Object>();
12017+
TryCatch try_catch(context->GetIsolate());
12018+
v8::Maybe<v8::PropertyAttribute> result =
12019+
proxy->GetRealNamedPropertyAttributesInPrototypeChain(context.local(),
12020+
v8_str("p"));
12021+
CHECK(result.IsNothing());
12022+
CHECK(try_catch.HasCaught());
12023+
CHECK(try_catch.Exception()
12024+
.As<Object>()
12025+
->Get(context.local(), v8_str("message"))
12026+
.ToLocalChecked()
12027+
->StrictEquals(v8_str("abc")));
12028+
}
12029+
}
1198812030

1198912031
static void ThrowingCallbackWithTryCatch(
1199012032
const v8::FunctionCallbackInfo<v8::Value>& args) {

0 commit comments

Comments
 (0)