Tighten up name filters on Unix. Fixes bug 168.

This commit is contained in:
James Turner 2010-11-15 23:23:40 +00:00
parent 9f88b077ee
commit 56c520f455

View File

@ -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;
}
}