已关闭
[module_manager] ClassifyLoadError ctx.path 空指针解引用 + LoadNativeModule 6 参 ABI 破坏 #2169
张昊峥创建于  7月24日关闭于  7月25日
张昊峥
张昊峥
7月24日 创建

背景

commit 5aa350f4 feat: add loadErrInfo for LoadNativeModule to return precise error infoNativeModuleManager::LoadNativeModule 新增了第 7 个参数 std::string* loadErrInfo,并在加载失败路径上引入了 ClassifyLoadError 做错误归类。该提交引入了两个回归问题:

问题 1:ClassifyLoadError 空指针解引用(崩溃)

module_manager/native_module_manager.cpp 中:

} else if (ctx.isAppModule && !ctx.pathRegistered) {
    *loadErrInfo = std::string("app lib path not registered in namespace '") + ctx.path + "'";
}

ctx.path 未判空。当 isAppModule == truepath == nullptr 时:

  1. LoadNativeModule 入口仅校验 moduleNamerelativePath,未校验 path
  2. 多个调用方直接传 nullptr 作为 path(ark_native_engine.cpp:825 / :828 / :1526),isAppModule 由上层决定可为 true
  3. FindNativeModuleByDisk 中,path == nullptrIsExistedPath(nullptr) 返回 false(内部 pathKey && ... 短路),因此 dlopenFailed 保持 false
  4. 走到 ClassifyLoadErrorelse if (ctx.isAppModule && !ctx.pathRegistered) 分支 → std::string + nullptr → UB(libc++ 下基本必崩)。

触发场景:应用侧 NAPI 模块 .so.abc 均加载失败(打包错误/缺符号等),且走 4 参或 GetModuleFromName 调用路径。

问题 2:LoadNativeModule ABI 破坏(三方应用调用失败)

签名变更:

// 改前(三方 App 链接的 mangling)
NativeModule* LoadNativeModule(const char* moduleName, const char* path, bool isAppModule,
    std::string& errInfo, bool internal = false, const char* relativePath = "");

// 改后(当前 master)
NativeModule* LoadNativeModule(const char* moduleName, const char* path, bool isAppModule,
    std::string& errInfo, bool internal = false, const char* relativePath = "",
    std::string* loadErrInfo = nullptr);

Itanium C++ ABI 下默认参数不进 mangled name,参数个数变化 → 老 mangled 符号消失。三方应用通过 dlopen(libace_napi.z.so) + 调用旧 6 参签名在新 so 上找不到符号 → 运行期解析失败。

期望

  1. ClassifyLoadError 内对 ctx.path 做判空(局部修复,不改加载行为)。
  2. 新增 6 参 LoadNativeModule 重载以保留旧 mangled 符号导出,行为委托到 7 参主版本(loadErrInfo = nullptr)。
likedislike
openharmony_ci
openharmony_ci成员
7月24日 评论:

感谢提交Issue!关于Issue的交互操作,请访问OpenHarmony社区支持命令清单。如果有问题,请联系 [@weng-changcheng](https://gitcode.com/weng-changcheng) [@xliu-huanwei](https://gitcode.com/xliu-huanwei) [@gong_19901](https://gitcode.com/gong_19901) 。如果需要调整订阅PR、Issue的变更状态,请访问链接


Thanks for submitting the issue. For more commands, please visit OpenHarmony Command List. If you have any questions, please refer to committer gitcode for help. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
openharmony_ciopenharmony_ci成员
7月24日 添加了label:waiting_for_assign
张昊峥张昊峥
7月24日 关联了pull request:fix(module_manager): null-guard ClassifyLoadError path; restore 6-param LoadNativeModule ABI
openharmony_ciopenharmony_ci成员
7月25日 关闭了 issue
openharmony_ciopenharmony_ci成员
7月25日 issue状态由 待办的 改变为 已完成
张昊峥张昊峥
7月29日 关联了pull request:fix(module_manager): null-guard ClassifyLoadError path; restore LoadNativeModule ABI [backport to 7.0]