Skip to content

Commit ab2b091

Browse files
committed
vm: fix crash when setting __proto__ on context's globalThis
1 parent dccd25e commit ab2b091

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/node_contextify.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,11 @@ void ContextifyContext::PropertySetterCallback(
529529

530530
if (ctx->sandbox()->Set(context, property, value).IsNothing()) return;
531531

532-
Local<Value> desc;
533-
if (is_declared_on_sandbox &&
534-
ctx->sandbox()
535-
->GetOwnPropertyDescriptor(context, property)
536-
.ToLocal(&desc)) {
532+
if (is_declared_on_sandbox) {
533+
Local<Value> desc;
534+
bool success = ctx->sandbox()->GetOwnPropertyDescriptor(context, property).ToLocal(&desc);
535+
if (!success || desc->IsUndefined()) return;
536+
537537
Environment* env = Environment::GetCurrent(context);
538538
Local<Object> desc_obj = desc.As<Object>();
539539

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
require('../common');
3+
4+
// Setting __proto__ on vm context's globalThis should not causes a crash
5+
// Regression test for https://github.com/nodejs/node/issues/47798
6+
7+
const vm = require('vm');
8+
const context = vm.createContext();
9+
10+
const contextGlobalThis = vm.runInContext('this', context);
11+
12+
// Should not crash.
13+
contextGlobalThis.__proto__ = null; // eslint-disable-line no-proto

0 commit comments

Comments
 (0)