Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7092 - Fixed bug when deleting function with multiple function tags

dragonmacherc098bf9afa14
diff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/cmd/function/DeleteFunctionCmdTest.java b/Ghidra/Features/Base/src/test/java/ghidra/app/cmd/function/DeleteFunctionCmdTest.java
index d913f035ca..f60e3f683e 100644
--- a/Ghidra/Features/Base/src/test/java/ghidra/app/cmd/function/DeleteFunctionCmdTest.java
+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/cmd/function/DeleteFunctionCmdTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -117,7 +117,7 @@ public class DeleteFunctionCmdTest extends AbstractGenericTest {
/*
* This is a regression test. Make sure function deletes work with multiple tags.
- * See issue #9386.
+ * See github issue #9386.
*/
@Test
public void testDeleteFunctionWithMultipleTags() {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionDB.java
index 387ad5cd71..1dd4f1c754 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionDB.java
@@ -1528,21 +1528,21 @@ public class FunctionDB extends DbObject implements Function {
// cache will have the current tag state unless tags have been deleted or edited; in
// those cases the validity check will fail and we'll be forced to go back to
// the db.
+ Set<FunctionTag> copy = new HashSet<>();
try (Closeable c = lock.read()) {
- if (refreshIfNeeded() && tags != null) {
- return tags;
+ if (!refreshIfNeeded() || tags == null) {
+ FunctionTagManagerDB tagManager =
+ (FunctionTagManagerDB) manager.getFunctionTagManager();
+ tags = tagManager.getFunctionTagsByFunctionID(getID());
}
- // Get a list of all tag records that map to our function.
- FunctionTagManagerDB tagManager =
- (FunctionTagManagerDB) manager.getFunctionTagManager();
- tags = tagManager.getFunctionTagsByFunctionID(getID());
+ copy.addAll(tags);
}
catch (IOException e) {
manager.dbError(e);
}
- return tags;
+ return copy;
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java
index 3e77ca4d6d..f4e7abea04 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/function/FunctionManagerDB.java
@@ -430,7 +430,7 @@ public class FunctionManagerDB implements FunctionManager {
}
// Remove all tag mappings associated with this function
- for (FunctionTag tag : new ArrayList<>(function.getTags())) {
+ for (FunctionTag tag : function.getTags()) {
function.removeTag(tag.getName());
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Function.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Function.java
index 3987240ae0..b9166f0b06 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Function.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/Function.java
@@ -283,7 +283,7 @@ public interface Function extends Namespace {
/**
* Return all {@link FunctionTag} objects associated with this function.
*
- * @return set of tag names
+ * @return set of tags
*/
public Set<FunctionTag> getTags();