From 210d5cb4513b7ba67b6990624cf19fee1ee0a9f9 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Mon, 11 Jul 2016 18:05:23 -0400 Subject: Fixed issue that could cause core_filename_ends_with() to return true when extension.size() > filename.size() --- src/lib/util/corefile.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/lib/util/corefile.cpp') diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp index 5c530b41f30..c06426015f7 100644 --- a/src/lib/util/corefile.cpp +++ b/src/lib/util/corefile.cpp @@ -1298,15 +1298,16 @@ bool core_filename_ends_with(const std::string &filename, const std::string &ext { auto namelen = filename.length(); auto extlen = extension.length(); - bool matches = true; + // first if the extension is bigger than the name, we definitely don't match + bool matches = namelen >= extlen; + // work backwards checking for a match - while (extlen > 0 && namelen > 0) + while (matches && extlen > 0 && namelen > 0) + { if (tolower((UINT8)filename[--namelen]) != tolower((UINT8)extension[--extlen])) - { matches = false; - break; - } + } return matches; } -- cgit v1.2.3-70-g09d2