vm: fix crash when setting __proto__ on context's globalThis

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Feng Yu authored and GitHub committed 2023-05-15 09:24:15 +00:00
1 parent 8b3777d0c8
commit 6bbf2a57fc
2 files changed
+15 -1

No files matched your search

+2 -1
View File
@@ -530,7 +530,8 @@ void ContextifyContext::PropertySetterCallback(
if (is_declared_on_sandbox &&
ctx->sandbox()
->GetOwnPropertyDescriptor(context, property)
.ToLocal(&desc)) {
.ToLocal(&desc) &&
!desc->IsUndefined()) {
Environment* env = Environment::GetCurrent(context);
Local<Object> desc_obj = desc.As<Object>();
@@ -0,0 +1,13 @@
'use strict';
require('../common');
// Setting __proto__ on vm context's globalThis should not cause 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