From 9b007fdd9a02663959ba3843f849cfd5d118b45d Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Fri, 3 Dec 2021 11:17:21 -0800 Subject: [PATCH] Fix superpmi.exe handling of exclusion lists superpmi.exe has the concept of an exclusion list file which is automatically read and processed when reading a .mch file. (I'm not sure if anyone actually uses it.) So, when opening a `t.mch` file, it looks for an adjacent `t.mch.exc` and then `t.exc` file. There was a bug where it would also look for a `t` file (the comments say it takes t.exc.mch and looks for t.exc, but it didn't check for that). In my case when I was testing, I actually had a `t` directory (not file), which it found, but then emitted an error trying to load. So, two fixes: 1. For `t.mch`, don't look for `t`. 2. Check all cases for being a directory, and fail if any name is a directory. --- .../superpmi-shared/methodcontextreader.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontextreader.cpp b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontextreader.cpp index c5e63bf688a33..4b59b72114e9e 100644 --- a/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontextreader.cpp +++ b/src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontextreader.cpp @@ -42,25 +42,25 @@ std::string MethodContextReader::CheckForPairedFile(const std::string& fileName, { std::string tmp = to_lower(origSuffix); - // First, check to see if foo.origSuffix exists + // First, check to see if foo.origSuffix exists and is not a directory name size_t suffix_offset = fileName.find_last_of('.'); - if ((SSIZE_T)suffix_offset <= 0 || (tmp != to_lower(fileName.substr(suffix_offset))) || - (GetFileAttributesA(fileName.c_str()) == INVALID_FILE_ATTRIBUTES)) + if ((SSIZE_T)suffix_offset <= 0 || (tmp != to_lower(fileName.substr(suffix_offset)))) + return std::string(); + + DWORD attribs = GetFileAttributesA(fileName.c_str()); + if ((attribs == INVALID_FILE_ATTRIBUTES) || (attribs & FILE_ATTRIBUTE_DIRECTORY)) return std::string(); // next, check foo.orig.new from foo.orig tmp = fileName + newSuffix; - if (GetFileAttributesA(tmp.c_str()) != INVALID_FILE_ATTRIBUTES) - return tmp; - - // Now let's check for foo.new from foo.new.orig - tmp = fileName.substr(0, suffix_offset); - if (GetFileAttributesA(tmp.c_str()) != INVALID_FILE_ATTRIBUTES) + attribs = GetFileAttributesA(tmp.c_str()); + if ((attribs != INVALID_FILE_ATTRIBUTES) && !(attribs & FILE_ATTRIBUTE_DIRECTORY)) return tmp; - // Finally, lets try foo.orig from foo.new - tmp += newSuffix; - if (GetFileAttributesA(tmp.c_str()) != INVALID_FILE_ATTRIBUTES) + // Finally, lets try foo.new from foo.orig + tmp = fileName.substr(0, suffix_offset) + newSuffix; + attribs = GetFileAttributesA(tmp.c_str()); + if ((attribs != INVALID_FILE_ATTRIBUTES) && !(attribs & FILE_ATTRIBUTE_DIRECTORY)) return tmp; return std::string();