summaryrefslogtreecommitdiff
path: root/view/sharedcache
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-14 01:44:28 -0400
committerMason Reed <mason@vector35.com>2025-04-14 03:20:51 -0400
commit664bdcd29761844ba9558f9c5fd43949009424e3 (patch)
treee68cb93a918ad144c4c463323bd966ac89741fe0 /view/sharedcache
parentbf64859f5aa261fa8db7bfdd9af4f67826ff4e5b (diff)
[SharedCache] Fix project folder comparison crash
Fixes https://github.com/Vector35/binaryninja-api/issues/6629
Diffstat (limited to 'view/sharedcache')
-rw-r--r--view/sharedcache/core/SharedCacheBuilder.cpp5
-rw-r--r--view/sharedcache/core/Utility.cpp9
-rw-r--r--view/sharedcache/core/Utility.h2
3 files changed, 13 insertions, 3 deletions
diff --git a/view/sharedcache/core/SharedCacheBuilder.cpp b/view/sharedcache/core/SharedCacheBuilder.cpp
index 5c3ea0d8..ac2990fa 100644
--- a/view/sharedcache/core/SharedCacheBuilder.cpp
+++ b/view/sharedcache/core/SharedCacheBuilder.cpp
@@ -83,9 +83,8 @@ size_t SharedCacheBuilder::AddProjectFolder(Ref<ProjectFolder> folder)
const auto currentFileName = file.GetName();
// Skip files not in the folder.
- if (const auto currentFolder = file.GetFolder(); folder)
- if (currentFolder->GetId() != folder->GetId())
- return false;
+ if (!IsSameFolder(file.GetFolder(), folder))
+ return false;
// Ok, we are now _sure_ that this file _might_ be a part of the cache, lets try and process it!
return AddFile(currentFilePath, currentFileName, CacheEntryType::Secondary);
diff --git a/view/sharedcache/core/Utility.cpp b/view/sharedcache/core/Utility.cpp
index 583770e6..0cffc03e 100644
--- a/view/sharedcache/core/Utility.cpp
+++ b/view/sharedcache/core/Utility.cpp
@@ -136,3 +136,12 @@ std::string BaseFileName(const std::string& path)
return path.substr(lastSlashPos + 1);
return path;
}
+
+bool IsSameFolder(Ref<ProjectFolder> a, Ref<ProjectFolder> b)
+{
+ if (!a && !b)
+ return true;
+ if (a && b)
+ return a->GetId() == b->GetId();
+ return false;
+}
diff --git a/view/sharedcache/core/Utility.h b/view/sharedcache/core/Utility.h
index af242bb6..81c3b583 100644
--- a/view/sharedcache/core/Utility.h
+++ b/view/sharedcache/core/Utility.h
@@ -40,6 +40,8 @@ void ApplySymbol(BinaryNinja::Ref<BinaryNinja::BinaryView> view, BinaryNinja::Re
// /blah/foo/bar/libObjCThing.dylib -> libObjCThing.dylib
std::string BaseFileName(const std::string& path);
+bool IsSameFolder(BinaryNinja::Ref<BinaryNinja::ProjectFolder> a, BinaryNinja::Ref<BinaryNinja::ProjectFolder> b);
+
// Represents a range of addresses [start, end).
// Note that `end` is not included within the range.
struct AddressRange