From: James Turner Date: Mon, 15 Nov 2010 23:23:40 +0000 (+0000) Subject: Tighten up name filters on Unix. Fixes bug 168. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=56c520f455f375520ea0db757f6287cf754b5be1;p=simgear.git Tighten up name filters on Unix. Fixes bug 168. --- diff --git a/simgear/misc/sg_dir.cxx b/simgear/misc/sg_dir.cxx index b8a68991..59f96dfa 100644 --- a/simgear/misc/sg_dir.cxx +++ b/simgear/misc/sg_dir.cxx @@ -106,6 +106,8 @@ PathList Dir::children(int types, const std::string& nameFilter) const return result; } + int filterLen = nameFilter.size(); + while (true) { struct dirent* entry = readdir(dp); if (!entry) { @@ -144,7 +146,13 @@ PathList Dir::children(int types, const std::string& nameFilter) const } if (!nameFilter.empty()) { - if (strstr(entry->d_name, nameFilter.c_str()) == NULL) { + int nameLen = strlen(entry->d_name); + if (nameLen < filterLen) { + continue; // name is shorter than the filter + } + + char* nameSuffix = entry->d_name + (nameLen - filterLen); + if (strcmp(nameSuffix, nameFilter.c_str())) { continue; } }