Skip to content

Commit 2bd869d

Browse files
F3n67utargos
authored andcommitted
vm: fix crash when setting __proto__ on context's globalThis
PR-URL: #47939 Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 17befe0 commit 2bd869d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/node_contextify.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ void ContextifyContext::PropertySetterCallback(
530530
if (is_declared_on_sandbox &&
531531
ctx->sandbox()
532532
->GetOwnPropertyDescriptor(context, property)
533-
.ToLocal(&desc)) {
533+
.ToLocal(&desc) &&
534+
!desc->IsUndefined()) {
534535
Environment* env = Environment::GetCurrent(context);
535536
Local<Object> desc_obj = desc.As<Object>();
536537

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 cause 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)