From 26c57c4444032be786fe5ab1b3b015b7770a8790 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 19 Dec 2022 10:53:04 -0600 Subject: [PATCH] Check that malloc'd settings isn't null --- bindings/java/c_kzg_4844_jni.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bindings/java/c_kzg_4844_jni.c b/bindings/java/c_kzg_4844_jni.c index 5de5fe5..0698974 100644 --- a/bindings/java/c_kzg_4844_jni.c +++ b/bindings/java/c_kzg_4844_jni.c @@ -44,7 +44,12 @@ JNIEXPORT void JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_loadTrustedSetup__Ljav throw_exception(env, "Trusted Setup is already loaded. Free it before loading a new one."); return; } + settings = malloc(sizeof(KZGSettings)); + if (settings == NULL) + { + throw_exception(env, "Failed to allocate memory for settings."); + } const char *file_native = (*env)->GetStringUTFChars(env, file, 0); @@ -78,7 +83,12 @@ JNIEXPORT void JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_loadTrustedSetup___3BJ throw_exception(env, "Trusted Setup is already loaded. Free it before loading a new one."); return; } + settings = malloc(sizeof(KZGSettings)); + if (settings == NULL) + { + throw_exception(env, "Failed to allocate memory for settings."); + } jbyte *g1_native = (*env)->GetByteArrayElements(env, g1, NULL); jbyte *g2_native = (*env)->GetByteArrayElements(env, g2, NULL);