Skip to content

Commit

Permalink
vm: fix crash when setting __proto__ on context's globalThis
Browse files Browse the repository at this point in the history
  • Loading branch information
Finn Yu committed May 9, 2023
1 parent dccd25e commit 32efab2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,11 @@ void ContextifyContext::PropertySetterCallback(

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

Local<Value> desc;
if (is_declared_on_sandbox &&
ctx->sandbox()
->GetOwnPropertyDescriptor(context, property)
.ToLocal(&desc)) {
if (is_declared_on_sandbox) {
Local<Value> desc;
bool success = ctx->sandbox()->GetOwnPropertyDescriptor(context, property).ToLocal(&desc);
if (!success || desc->IsUndefined()) return;

Environment* env = Environment::GetCurrent(context);
Local<Object> desc_obj = desc.As<Object>();

Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-vm-set-proto-null-on-globalthis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
require('../common');

// Setting __proto__ on vm context's globalThis should not causes a crash
// Regression test for https://github.com/nodejs/node/issues/47798

const vm = require('vm');
const context = vm.createContext();

const contextGlobalThis = vm.runInContext('this', context);

// Should not crash.
contextGlobalThis.__proto__ = null; // eslint-disable-line no-proto

0 comments on commit 32efab2

Please sign in to comment.