From: Matt Corallo Date: Sat, 1 May 2021 00:01:33 +0000 (+0000) Subject: Handle LDKStr in other structs and fix string conversion overread X-Git-Tag: v0.0.98~1^2~17 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=d2a89f05dbc2f27fe9aece9d55e7ea627080186f;p=ldk-java Handle LDKStr in other structs and fix string conversion overread --- diff --git a/genbindings.py b/genbindings.py index 4b5ef5dc..3d5bac97 100755 --- a/genbindings.py +++ b/genbindings.py @@ -260,6 +260,7 @@ def java_c_types(fn_arg, ret_arr_len): fn_ty_arg = "Ljava/lang/String;" fn_arg = fn_arg[6:].strip() elif fn_arg.startswith("LDKStr"): + rust_obj = "LDKStr" java_ty = "String" c_ty = "jstring" fn_ty_arg = "Ljava/lang/String;" diff --git a/java_strings.py b/java_strings.py index 0c86200e..43265f44 100644 --- a/java_strings.py +++ b/java_strings.py @@ -309,12 +309,12 @@ typedef jbyteArray int8_tArray; static inline jstring str_ref_to_java(JNIEnv *env, const char* chars, size_t len) { // Sadly we need to create a temporary because Java can't accept a char* without a 0-terminator - char* err_buf = MALLOC(len + 1, "str conv buf"); - memcpy(err_buf, chars, len); - err_buf[len] = 0; - jstring err_conv = (*env)->NewStringUTF(env, chars); - FREE(err_buf); - return err_conv; + char* conv_buf = MALLOC(len + 1, "str conv buf"); + memcpy(conv_buf, chars, len); + conv_buf[len] = 0; + jstring ret = (*env)->NewStringUTF(env, conv_buf); + FREE(conv_buf); + return ret; } static inline LDKStr java_to_owned_str(JNIEnv *env, jstring str) { uint64_t str_len = (*env)->GetStringUTFLength(env, str);