Hello all.
I'm calling java code from C.
I'm getting lots of sigsegv inside libjvm.
I'm afraid it can depend on something wrong I'm doing before invoking the actual java method.
The java class I'm calling here is using a remote RMI object to perform a passphrase decryption and should return clear text to the caller.
Here is the invocation code:
I've carefully checked the incoming params.
They are correctly allocated null terminated strings.
I can post the Java method as well, unless someone at a first glance will see the wrong stuff in what am I doing here.
Oh, I forgot to mention that sometimes the code works properly!!!
Thanks in advance and apologize if a silly question.
:adore:
\c
I'm calling java code from C.
I'm getting lots of sigsegv inside libjvm.
I'm afraid it can depend on something wrong I'm doing before invoking the actual java method.
The java class I'm calling here is using a remote RMI object to perform a passphrase decryption and should return clear text to the caller.
Here is the invocation code:
Code:
int do_p_stuff_1p( char * encdec_client_path, char *classPath, char *libraryPath, char *crypt_pwd, char *dariempire) {
// jni per interfacciare EDS
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[3];
int nbOptions;
jint res;
jclass myJavaClass;
/** Start the Java Virtual Machine **/
nbOptions=0;
options[0].optionString = classPath; nbOptions++;
options[1].optionString = libraryPath; nbOptions++;
vm_args.version = JNI_VERSION_1_2; /* Specifies the JNI
version used */
vm_args.options = options;
vm_args.nOptions = nbOptions;
vm_args.ignoreUnrecognized = JNI_TRUE; /* JNI won't
complain about unrecognized options */
res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
/*
* Create an instance of the Class
*/
myJavaClass = (*env)->FindClass(env, encdec_client_path);
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
return JAVAEXCEPTION;
}
jmethodID mid;
jstring jstr, jstrReturn;
jclass stringClass;
jobjectArray args;
const char * msg;
mid = (*env)->GetStaticMethodID(env, myJavaClass, "execute",
"([Ljava/lang/String;)Ljava/lang/String;");
if (mid == NULL) {
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
return JAVAEXCEPTION;
}
}
jstr = (*env)->NewStringUTF(env, "DC");
if (jstr == NULL) {
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
return JAVAEXCEPTION;
}
}
stringClass = (*env)->FindClass(env, "java/lang/String");
args = (*env)->NewObjectArray(env, 3, stringClass, jstr);
if (args == NULL) {
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
return JAVAEXCEPTION;
}
}
jstr = (*env)->NewStringUTF(env, crypt_pwd);
(*env)->SetObjectArrayElement(env, args, 2, jstr);
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
return JAVAEXCEPTION;
}
// THIS IS CAUSING PROBLEMS
jstrReturn = (*env)->CallStaticObjectMethod(env, myJavaClass, mid, args);
msg = (const char *)(*env)->GetStringUTFChars(env, jstrReturn,NULL);
if ((*env)->ExceptionOccurred(env)) {
(*env)->ExceptionDescribe(env);
return JAVAEXCEPTION;
}
if(jvm!=NULL) {
if((*jvm)->DestroyJavaVM(jvm)!=0) {
return JAVAEXCEPTION;
}
}
if(strstr(msg,"ERROR")!=NULL || strstr(msg,"\n")!=NULL) {
return EDERROR;
}
sprintf(dariempire,"%s", msg);
return 0;
}
I've carefully checked the incoming params.
They are correctly allocated null terminated strings.
I can post the Java method as well, unless someone at a first glance will see the wrong stuff in what am I doing here.
Oh, I forgot to mention that sometimes the code works properly!!!
Thanks in advance and apologize if a silly question.
:adore:
\c
Last edited: