From e184eb4a232243f757b0b21bdf348858485a54ce Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 17 Oct 2021 02:02:53 +0800 Subject: [PATCH] Fix UB of loading modules - The lambda here infers its return type as `std::string`, and since `info` is `const`, the labmda copies `info.name` and returns a `std::string&&`. After captured by the `std::string_view`, the `std::string&&` return value deconstructs and makes `std::string_view` refers to a dangling pointer. --- native/jni/core/module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/jni/core/module.cpp b/native/jni/core/module.cpp index 65b2ee3df..102a6caff 100644 --- a/native/jni/core/module.cpp +++ b/native/jni/core/module.cpp @@ -753,7 +753,7 @@ void remove_modules() { void exec_module_scripts(const char *stage) { vector module_names; std::transform(modules->begin(), modules->end(), std::back_inserter(module_names), - [](const module_info &info) { return info.name; }); + [](const module_info &info) -> string_view { return info.name; }); exec_module_scripts(stage, module_names); }