Skip to content

Commit 0d0fad8

Browse files
F3n67uMoLow
authored andcommitted
vm: fix crash when setting __proto__ on context's globalThis
PR-URL: #47939 Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 866ed6a commit 0d0fad8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/node_contextify.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ void ContextifyContext::PropertySetterCallback(
535535
if (is_declared_on_sandbox &&
536536
ctx->sandbox()
537537
->GetOwnPropertyDescriptor(context, property)
538-
.ToLocal(&desc)) {
538+
.ToLocal(&desc) &&
539+
!desc->IsUndefined()) {
539540
Environment* env = Environment::GetCurrent(context);
540541
Local<Object> desc_obj = desc.As<Object>();
541542

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