From ad5d9a5234baf8f588c6a522ab4635b9f9ac0302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Tue, 11 Jan 2022 20:38:00 +0000 Subject: [PATCH] src: gracefully handle errors in GetX509NameObject PR-URL: https://github.com/nodejs/node/pull/41490 Co-authored-by: Anna Henningsen Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig --- src/crypto/crypto_common.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 4be308fb655017..53d9d949457c8f 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -1035,17 +1035,26 @@ static MaybeLocal GetX509NameObject(Environment* env, X509* cert) { // change here without breaking things. Note that this creates nested data // structures, yet still does not allow representing Distinguished Names // accurately. - if (result->HasOwnProperty(env->context(), v8_name).ToChecked()) { - Local accum = - result->Get(env->context(), v8_name).ToLocalChecked(); + bool multiple; + if (!result->HasOwnProperty(env->context(), v8_name).To(&multiple)) { + return MaybeLocal(); + } else if (multiple) { + Local accum; + if (!result->Get(env->context(), v8_name).ToLocal(&accum)) { + return MaybeLocal(); + } if (!accum->IsArray()) { accum = Array::New(env->isolate(), &accum, 1); - result->Set(env->context(), v8_name, accum).Check(); + if (result->Set(env->context(), v8_name, accum).IsNothing()) { + return MaybeLocal(); + } } Local array = accum.As(); - array->Set(env->context(), array->Length(), v8_value).Check(); - } else { - result->Set(env->context(), v8_name, v8_value).Check(); + if (array->Set(env->context(), array->Length(), v8_value).IsNothing()) { + return MaybeLocal(); + } + } else if (result->Set(env->context(), v8_name, v8_value).IsNothing()) { + return MaybeLocal(); } }