mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-20 08:06:18 +00:00
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:
+15
-9
@@ -68,15 +68,21 @@ LuaEngine::search_lua_path(lua_State* l_state) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Tokenize path using ';' as delimiter
|
// Tokenize path using ';' as delimiter
|
||||||
size_t pos = 0, end;
|
for (size_t pos = 0, end = 0; end != std::string::npos; pos = end + 1) {
|
||||||
while ((end = lua_path.find(';', pos)) != std::string::npos) {
|
end = lua_path.find(';', pos);
|
||||||
std::string file_path(lua_path.substr(pos, end - pos));
|
|
||||||
size_t ppos = 0;
|
std::string file_path((end == std::string::npos)
|
||||||
while ((ppos = file_path.find('?')) != std::string::npos) {
|
? lua_path.substr(pos)
|
||||||
file_path.replace(ppos, 1, LuaEngine::module_name);
|
: lua_path.substr(pos, end - pos));
|
||||||
}
|
|
||||||
if (file_exists(file_path)) {
|
if (!file_path.empty()) {
|
||||||
return file_path;
|
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 "";
|
return "";
|
||||||
|
|||||||
Reference in New Issue
Block a user