Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ void ContextifyContext::PropertySetterCallback(
if (is_declared_on_sandbox &&
F3n67u marked this conversation as resolved.
Show resolved Hide resolved
ctx->sandbox()
->GetOwnPropertyDescriptor(context, property)
.ToLocal(&desc)) {
.ToLocal(&desc) &&
!desc->IsUndefined()) {
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 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