11#include " node.h"
22#include " node_internals.h"
3+ #include " node_errors.h"
34#include " base_object.h"
45#include " base_object-inl.h"
56#include " env-inl.h"
@@ -617,8 +618,13 @@ void EnvGetter(Local<Name> property,
617618 if ((result > 0 || GetLastError () == ERROR_SUCCESS) &&
618619 result < arraysize (buffer)) {
619620 const uint16_t * two_byte_buffer = reinterpret_cast <const uint16_t *>(buffer);
620- Local<String> rc = String::NewFromTwoByte (isolate, two_byte_buffer);
621- return info.GetReturnValue ().Set (rc);
621+ v8::MaybeLocal<String> rc = String::NewFromTwoByte (
622+ isolate, two_byte_buffer, v8::NewStringType::kNormal );
623+ if (rc.IsEmpty ()) {
624+ isolate->ThrowException (ERR_STRING_TOO_LONG (isolate));
625+ return ;
626+ }
627+ return info.GetReturnValue ().Set (rc.ToLocalChecked ());
622628 }
623629#endif
624630}
@@ -759,10 +765,17 @@ void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
759765 }
760766 const uint16_t * two_byte_buffer = reinterpret_cast <const uint16_t *>(p);
761767 const size_t two_byte_buffer_len = s - p;
762- argv[idx] = String::NewFromTwoByte (isolate,
763- two_byte_buffer,
764- String::kNormalString ,
765- two_byte_buffer_len);
768+ v8::MaybeLocal<String> rc =
769+ String::NewFromTwoByte (isolate,
770+ two_byte_buffer,
771+ v8::NewStringType::kNormal ,
772+ two_byte_buffer_len);
773+ if (rc.IsEmpty ()) {
774+ isolate->ThrowException (ERR_STRING_TOO_LONG (isolate));
775+ FreeEnvironmentStringsW (environment);
776+ return ;
777+ }
778+ argv[idx] = rc.ToLocalChecked ();
766779 if (++idx >= arraysize (argv)) {
767780 fn->Call (ctx, envarr, idx, argv).ToLocalChecked ();
768781 idx = 0 ;
0 commit comments