Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 184fc2d

Browse files
committedMay 9, 2023
vm: fix crash when setting __proto__ on context's globalThis
1 parent dccd25e commit 184fc2d

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed
 

‎src/node_contextify.cc

+7-5
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,13 @@ 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()
535+
->GetOwnPropertyDescriptor(context, property)
536+
.ToLocal(&desc);
537+
if (!success || desc->IsUndefined()) return;
538+
537539
Environment* env = Environment::GetCurrent(context);
538540
Local<Object> desc_obj = desc.As<Object>();
539541

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)
Please sign in to comment.