node bindings: Add some missing memory allocation checks (#64)

* node bindings: Add some memory allocation checks

* fixup! node bindings: Add some memory allocation checks
This commit is contained in:
George Kadianakis 2023-01-13 18:24:25 +02:00 committed by GitHub
parent c72ea8e1dc
commit 158977085c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -170,6 +170,10 @@ Napi::Value ComputeAggregateKzgProof(const Napi::CallbackInfo& info) {
auto blobs_count = blobs_param.Length();
auto blobs = (Blob*)calloc(blobs_count, sizeof(Blob));
if (blobs == NULL) {
Napi::Error::New(env, "Error while allocating memory for blobs").ThrowAsJavaScriptException();
return env.Null();
};
for (uint32_t blob_index = 0; blob_index < blobs_count; blob_index++) {
Napi::Value blob = blobs_param[blob_index];
@ -216,7 +220,17 @@ Napi::Value VerifyAggregateKzgProof(const Napi::CallbackInfo& info) {
auto blobs_count = blobs_param.Length();
auto blobs = (Blob*)calloc(blobs_count, sizeof(Blob));
if (blobs == NULL) {
Napi::Error::New(env, "Error while allocating memory for blobs").ThrowAsJavaScriptException();
return env.Null();
};
auto commitments = (KZGCommitment*)calloc(blobs_count, sizeof(KZGCommitment));
if (commitments == NULL) {
free(blobs);
Napi::Error::New(env, "Error while allocating memory for commitments").ThrowAsJavaScriptException();
return env.Null();
};
C_KZG_RET ret;