Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
vm: fix crash when setting __proto__ on context's globalThis
  • Loading branch information
F3n67u committed May 9, 2023
commit 184fc2dd827940b4ef72d77bf77b837192efe37b
12 changes: 7 additions & 5 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,13 @@ 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