fix(lua): require(rtorrent) cause infinite loop

- missing `pos = end + 1` pos caused infinite loop

- there was no processing of the last element after the last ';', i.e. it was
  assumed that `lua_path` always has ';' in the last character
This commit is contained in:
PRESFIL
2025-06-11 18:34:26 +00:00
committed by Jari Sundell
parent 756e3bd5ae
commit a1ff6f5710
+15 -9
View File
@@ -68,15 +68,21 @@ LuaEngine::search_lua_path(lua_State* l_state) {
};
// Tokenize path using ';' as delimiter
size_t pos = 0, end;
while ((end = lua_path.find(';', pos)) != std::string::npos) {
std::string file_path(lua_path.substr(pos, end - pos));
size_t ppos = 0;
while ((ppos = file_path.find('?')) != std::string::npos) {
file_path.replace(ppos, 1, LuaEngine::module_name);
}
if (file_exists(file_path)) {
return file_path;
for (size_t pos = 0, end = 0; end != std::string::npos; pos = end + 1) {
end = lua_path.find(';', pos);
std::string file_path((end == std::string::npos)
? lua_path.substr(pos)
: lua_path.substr(pos, end - pos));
if (!file_path.empty()) {
size_t ppos = 0;
while ((ppos = file_path.find('?')) != std::string::npos) {
file_path.replace(ppos, 1, LuaEngine::module_name);
}
if (file_exists(file_path)) {
return file_path;
}
}
}
return "";