Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Android] Fix C++ Crash in WeexCore::NotifyLayout. (#2831)
Browse files Browse the repository at this point in the history
The return value of `jString2StrFast(env, instanceId)` could be `std::string(nullptr)`` if instanceId is `nullptr`, in which case the return value would cause crash.

```
    #00 pc 0x4aaec libweexcore.so (_ZNSt6__ndk16__treeINS_12__value_typeINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEPN8WeexCore14RenderPageBaseEEENS_19__map_value_compareIS7_SB_NS_4lessIS7_EELb1EEENS5_ISB_EEE13__lower_boundIS7_EENS_15__tree_iteratorISB_PNS_11__tree_nodeISB_PvEEiEERKT_SN_PNS_15__tree_end_nodeIPNS_16__tree_node_baseISL_EEEE+23)
    #1 pc 0x4aa6b libweexcore.so (_ZNSt6__ndk16__treeINS_12__value_typeINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEPN8WeexCore14RenderPageBaseEEENS_19__map_value_compareIS7_SB_NS_4lessIS7_EELb1EEENS5_ISB_EEE4findIS7_EENS_15__tree_iteratorISB_PNS_11__tree_nodeISB_PvEEiEERKT_+18)
    #2 pc 0x4907b libweexcore.so (_ZN8WeexCore13RenderManager7GetPageERKNSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE+6)
    #3 pc 0x5d2d5 libweexcore.so (_ZN8WeexCore18CoreSideInPlatform12NotifyLayoutERKNSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE+12)
 ```
  • Loading branch information
YorkShen authored and jianhan-he committed Aug 16, 2019
1 parent 16e476e commit f3c3c17
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion weex_core/Source/android/wrap/wx_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,13 @@ static jlongArray GetRenderFinishTime(JNIEnv* env, jobject jcaller,
// Notice that this method is invoked from main thread.
static jboolean NotifyLayout(JNIEnv* env, jobject jcaller, jstring instanceId) {
if (WeexCoreManager::Instance()->getPlatformBridge()) {
ScopedJStringUTF8 nativeString = ScopedJStringUTF8(env, instanceId);
const char* c_str_instance_id = nativeString.getChars();
std::string std_string_nstanceId = std::string(c_str_instance_id == nullptr ? "" : c_str_instance_id);
return WeexCoreManager::Instance()
->getPlatformBridge()
->core_side()
->NotifyLayout(jString2StrFast(env, instanceId));
->NotifyLayout(std_string_nstanceId);
}
return false;
}
Expand Down

0 comments on commit f3c3c17

Please sign in to comment.