From b3c62cfd86f554933208d11914e6cc8425506402 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 5 Oct 2020 13:43:04 -0700 Subject: [PATCH] src: remove toLocalChecked in crypto_context Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/35509 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott --- src/crypto/crypto_context.cc | 94 ++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc index 16a14ffcc89591..946dfc78ef2e4a 100644 --- a/src/crypto/crypto_context.cc +++ b/src/crypto/crypto_context.cc @@ -21,7 +21,6 @@ namespace node { using v8::Array; using v8::ArrayBufferView; -using v8::Boolean; using v8::Context; using v8::DontDelete; using v8::Exception; @@ -551,7 +550,9 @@ void SecureContext::SetEngineKey(const FunctionCallbackInfo& args) { const Utf8Value engine_id(env->isolate(), args[1]); EnginePointer engine = LoadEngineById(*engine_id, &errors); if (!engine) { - env->isolate()->ThrowException(errors.ToException(env).ToLocalChecked()); + Local exception; + if (errors.ToException(env).ToLocal(&exception)) + env->isolate()->ThrowException(exception); return; } @@ -1061,7 +1062,9 @@ void SecureContext::SetClientCertEngine( const node::Utf8Value engine_id(env->isolate(), args[0]); EnginePointer engine = LoadEngineById(*engine_id, &errors); if (!engine) { - env->isolate()->ThrowException(errors.ToException(env).ToLocalChecked()); + Local exception; + if (errors.ToException(env).ToLocal(&exception)) + env->isolate()->ThrowException(exception); return; } @@ -1079,7 +1082,10 @@ void SecureContext::GetTicketKeys(const FunctionCallbackInfo& args) { SecureContext* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); - Local buff = Buffer::New(wrap->env(), 48).ToLocalChecked(); + Local buff; + if (!Buffer::New(wrap->env(), 48).ToLocal(&buff)) + return; + memcpy(Buffer::Data(buff), wrap->ticket_key_name_, 16); memcpy(Buffer::Data(buff) + 16, wrap->ticket_key_hmac_, 16); memcpy(Buffer::Data(buff) + 32, wrap->ticket_key_aes_, 16); @@ -1143,45 +1149,59 @@ int SecureContext::TicketKeyCallback(SSL* ssl, HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - Local argv[] = { - Buffer::Copy(env, - reinterpret_cast(name), - kTicketPartSize).ToLocalChecked(), - Buffer::Copy(env, - reinterpret_cast(iv), - kTicketPartSize).ToLocalChecked(), - Boolean::New(env->isolate(), enc != 0) - }; - - Local ret = node::MakeCallback(env->isolate(), - sc->object(), - env->ticketkeycallback_string(), - arraysize(argv), - argv, - {0, 0}).ToLocalChecked(); + Local argv[3]; + + if (!Buffer::Copy( + env, + reinterpret_cast(name), + kTicketPartSize).ToLocal(&argv[0]) || + !Buffer::Copy( + env, + reinterpret_cast(iv), + kTicketPartSize).ToLocal(&argv[1])) { + return -1; + } + + argv[2] = env != 0 ? v8::True(env->isolate()) : v8::False(env->isolate()); + + Local ret; + if (!node::MakeCallback( + env->isolate(), + sc->object(), + env->ticketkeycallback_string(), + arraysize(argv), + argv, + {0, 0}).ToLocal(&ret) || + !ret->IsArray()) { + return -1; + } Local arr = ret.As(); - int r = - arr->Get(env->context(), - kTicketKeyReturnIndex).ToLocalChecked() - ->Int32Value(env->context()).FromJust(); + Local val; + if (!arr->Get(env->context(), kTicketKeyReturnIndex).ToLocal(&val) || + !val->IsInt32()) { + return -1; + } + + int r = val.As()->Value(); if (r < 0) return r; - Local hmac = arr->Get(env->context(), - kTicketKeyHMACIndex).ToLocalChecked(); - Local aes = arr->Get(env->context(), - kTicketKeyAESIndex).ToLocalChecked(); - if (Buffer::Length(aes) != kTicketPartSize) + Local hmac; + Local aes; + + if (!arr->Get(env->context(), kTicketKeyHMACIndex).ToLocal(&hmac) || + !arr->Get(env->context(), kTicketKeyAESIndex).ToLocal(&aes) || + Buffer::Length(aes) != kTicketPartSize) { return -1; + } if (enc) { - Local name_val = arr->Get(env->context(), - kTicketKeyNameIndex).ToLocalChecked(); - Local iv_val = arr->Get(env->context(), - kTicketKeyIVIndex).ToLocalChecked(); - - if (Buffer::Length(name_val) != kTicketPartSize || + Local name_val; + Local iv_val; + if (!arr->Get(env->context(), kTicketKeyNameIndex).ToLocal(&name_val) || + !arr->Get(env->context(), kTicketKeyIVIndex).ToLocal(&iv_val) || + Buffer::Length(name_val) != kTicketPartSize || Buffer::Length(iv_val) != kTicketPartSize) { return -1; } @@ -1272,7 +1292,9 @@ void SecureContext::GetCertificate(const FunctionCallbackInfo& args) { return args.GetReturnValue().SetNull(); int size = i2d_X509(cert, nullptr); - Local buff = Buffer::New(env, size).ToLocalChecked(); + Local buff; + if (!Buffer::New(env, size).ToLocal(&buff)) + return; unsigned char* serialized = reinterpret_cast( Buffer::Data(buff)); i2d_X509(cert, &serialized);