Fatal signal 11 (SIGSEGV), code 2, fault addr 0xb3d5e488 in tid 8058

会有一股神秘感。 提交于 2020-01-17 17:29:14

问题


I have a simple ndk code in my app and im keep getting this error in the logcat and app keep crashing. Here is the method where app is crashing:

char VAL1[] = "abcdef";
char VAL2[] = "123456";
char VAL3[] = "helloworld";
JNIEXPORT jstring JNICALL Java_com_livetv_android_apps_uktvnow_utils_Constants_getValue(JNIEnv *env , jobject thiz, jstring date, jstring completeUrl, jstring params){
const char *nativeDate = (env)->GetStringUTFChars(date, 0);
const char *nativeUrl = (env)->GetStringUTFChars(completeUrl,0);
const char *nativeParams = (env)->GetStringUTFChars(params,0);

char token[] = "";
jstring returnVal;
strcat(token,nativeDate);
strcat(token,VAL1);
strcat(token,nativeUrl);
strcat(token,VAL2);
strcat(token,nativeParams);
strcat(token,VAL3);

(env)->ReleaseStringUTFChars(date, nativeDate);
(env)->ReleaseStringUTFChars(completeUrl, nativeUrl);
(env)->ReleaseStringUTFChars(params, nativeParams);
returnVal =  (env)->NewStringUTF(token);
return returnVal;
}

The point of this method is to receive some string from java code and concatenate that string with some other values and return a jstring. Bellow is my LOGCAT:

06-03 17:20:05.452 8861-8861/com.livetv.android.apps.uktvnow A/libc:Fatal signal 11 (SIGSEGV), code 2, fault addr 0x745f7773 in tid 8861 (id.apps.uktvnow)
06-03 17:20:05.504 193-193/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 17:20:05.504 193-193/? I/DEBUG: Build fingerprint: 'google/occam/mako:5.1.1/LMY48T/2237560:user/release-keys'
06-03 17:20:05.504 193-193/? I/DEBUG: Revision: '11'
06-03 17:20:05.504 193-193/? I/DEBUG: ABI: 'arm'
06-03 17:20:05.504 193-193/? I/DEBUG: pid: 8861, tid: 8861, name: id.apps.uktvnow  >>> com.livetv.android.apps.uktvnow <<<
06-03 17:20:05.504 193-193/? I/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x745f7773
06-03 17:20:05.518 1320-1457/? I/Icing: Indexing done 56E76EE85DF9759742239162095EE2BD5D47F19A
06-03 17:20:05.525 193-193/? I/DEBUG:     r0 b75c5408  r1 6e656b70  r2 6e656b6f  r3 745f7777
06-03 17:20:05.526 193-193/? I/DEBUG:     r4 745f776f  r5 be872fa0  r6 b6e55dd4  r7 781cdd54
06-03 17:20:05.526 193-193/? I/DEBUG:     r8 be872ee4  r9 be872ef4  sl b520b2f0  fp b75c1370
06-03 17:20:05.526 193-193/? I/DEBUG:     ip b6e5196c  sp be872dc8  lr b4ff49f7  pc b517a92c  cpsr 300b0030
06-03 17:20:05.526 193-193/? I/DEBUG: backtrace:
06-03 17:20:05.526 193-193/? I/DEBUG:     #00 pc 0023992c  /system/lib/libart.so (art::Thread::DecodeJObject(_jobject*) const+151)
06-03 17:20:05.526 193-193/? I/DEBUG:     #01 pc 000b39f3  /system/lib/libart.so (art::ScopedCheck::CheckInstance(art::ScopedCheck::InstanceKind, _jobject*)+74)
06-03 17:20:05.526 193-193/? I/DEBUG:     #02 pc 000b45ef  /system/lib/libart.so (_ZN3art11ScopedCheck5CheckEbPKcz.constprop.129+762)
06-03 17:20:05.526 193-193/? I/DEBUG:     #03 pc 000be575  /system/lib/libart.so (art::CheckJNI::ReleaseStringUTFChars(_JNIEnv*, _jstring*, char const*)+68)
06-03 17:20:05.527 193-193/? I/DEBUG:     #04 pc 00000e69  /data/app/com.livetv.android.apps.uktvnow-2/lib/arm/libConstants.so (Java_com_livetv_android_apps_uktvnow_utils_Constants_getValue+156)
06-03 17:20:05.527 193-193/? I/DEBUG:     #05 pc 0114fe2a  /dev/ashmem/dalvik-non moving space (deleted)

So can please someone help me with this? Thanks.


回答1:


char[] token = "";

This means that token[] is an array of length 1, and you've appended a number of string to it of total length much more than 1, so you've corrupted the memory beyond it.

Solution: declare it big enough for the data you're gout to put into it.



来源:https://stackoverflow.com/questions/37614381/fatal-signal-11-sigsegv-code-2-fault-addr-0xb3d5e488-in-tid-8058

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!