diff options
author | Feng Yu <F3n67u@outlook.com> | 2023-05-15 02:24:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-15 09:24:15 +0000 |
commit | 6bbf2a57fcf33266c5859497f8cc32e1389a358a (patch) | |
tree | e8c8f2e6dc32f3fa1236441c1d220fc03fb45374 | |
parent | 8b3777d0c82c01229e724d84586fdc472fd4deda (diff) | |
download | node-new-6bbf2a57fcf33266c5859497f8cc32e1389a358a.tar.gz |
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>
-rw-r--r-- | src/node_contextify.cc | 3 | ||||
-rw-r--r-- | test/parallel/test-vm-set-proto-null-on-globalthis.js | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 7f9f71ba74..eb84d35985 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -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>(); diff --git a/test/parallel/test-vm-set-proto-null-on-globalthis.js b/test/parallel/test-vm-set-proto-null-on-globalthis.js new file mode 100644 index 0000000000..869124fa86 --- /dev/null +++ b/test/parallel/test-vm-set-proto-null-on-globalthis.js @@ -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 |