已关闭
[module_manager] ClassifyLoadError ctx.path 空指针解引用 + LoadNativeModule 6 参 ABI 破坏 #2169
张昊峥创建于 7月24日关闭于 7月25日
openharmony_ci
7月24日 评论:
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.


7月24日 添加了label:waiting_for_assign
7月24日 关联了pull request:fix(module_manager): null-guard ClassifyLoadError path; restore 6-param LoadNativeModule ABI
7月24日 关联了pull request:fix(module_manager): null-guard ClassifyLoadError path; restore 6-param LoadNativeModule ABI
7月25日 关闭了 issue
7月25日 issue状态由 待办的 改变为 已完成
7月29日 关联了pull request:fix(module_manager): null-guard ClassifyLoadError path; restore LoadNativeModule ABI [backport to 7.0]
7月29日 关联了pull request:fix(module_manager): null-guard ClassifyLoadError path; restore LoadNativeModule ABI [backport to 7.0]
背景
commit 5aa350f4 feat: add loadErrInfo for LoadNativeModule to return precise error info为NativeModuleManager::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 == true且path == nullptr时:LoadNativeModule入口仅校验moduleName与relativePath,未校验path。nullptr作为 path(ark_native_engine.cpp:825 / :828 / :1526),isAppModule由上层决定可为true。FindNativeModuleByDisk中,path == nullptr时IsExistedPath(nullptr)返回false(内部pathKey && ...短路),因此dlopenFailed保持false。ClassifyLoadError的else 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 上找不到符号 → 运行期解析失败。期望
ClassifyLoadError内对ctx.path做判空(局部修复,不改加载行为)。LoadNativeModule重载以保留旧 mangled 符号导出,行为委托到 7 参主版本(loadErrInfo = nullptr)。