Skip to content

Commit 6aec92f

Browse files
tniessenaddaleax
authored andcommitted
src: gracefully handle errors in GetX509NameObject
PR-URL: #41490 Co-authored-by: Anna Henningsen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 5129b7c commit 6aec92f

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/crypto/crypto_common.cc

+16-7
Original file line numberDiff line numberDiff line change
@@ -1082,17 +1082,26 @@ static MaybeLocal<Value> GetX509NameObject(Environment* env, X509* cert) {
10821082
// change here without breaking things. Note that this creates nested data
10831083
// structures, yet still does not allow representing Distinguished Names
10841084
// accurately.
1085-
if (result->HasOwnProperty(env->context(), v8_name).ToChecked()) {
1086-
Local<Value> accum =
1087-
result->Get(env->context(), v8_name).ToLocalChecked();
1085+
bool multiple;
1086+
if (!result->HasOwnProperty(env->context(), v8_name).To(&multiple)) {
1087+
return MaybeLocal<Value>();
1088+
} else if (multiple) {
1089+
Local<Value> accum;
1090+
if (!result->Get(env->context(), v8_name).ToLocal(&accum)) {
1091+
return MaybeLocal<Value>();
1092+
}
10881093
if (!accum->IsArray()) {
10891094
accum = Array::New(env->isolate(), &accum, 1);
1090-
result->Set(env->context(), v8_name, accum).Check();
1095+
if (result->Set(env->context(), v8_name, accum).IsNothing()) {
1096+
return MaybeLocal<Value>();
1097+
}
10911098
}
10921099
Local<Array> array = accum.As<Array>();
1093-
array->Set(env->context(), array->Length(), v8_value).Check();
1094-
} else {
1095-
result->Set(env->context(), v8_name, v8_value).Check();
1100+
if (array->Set(env->context(), array->Length(), v8_value).IsNothing()) {
1101+
return MaybeLocal<Value>();
1102+
}
1103+
} else if (result->Set(env->context(), v8_name, v8_value).IsNothing()) {
1104+
return MaybeLocal<Value>();
10961105
}
10971106
}
10981107

0 commit comments

Comments
 (0)