Skip to content

Ghidra is a software reverse engineering (SRE) framework

#9386 Fix function delete failing when 2 or more tags are applied

brothersw7ccc6e852bb0
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 757444e533..d913f035ca 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
@@ -115,6 +115,35 @@ public class DeleteFunctionCmdTest extends AbstractGenericTest {
program.endTransaction(transactionID, false);
}
+ /*
+ * This is a regression test. Make sure function deletes work with multiple tags.
+ * See issue #9386.
+ */
+ @Test
+ public void testDeleteFunctionWithMultipleTags() {
+
+ Address address = addr(0x0);
+ String defaultName = SymbolUtilities.getDefaultFunctionName(address);
+
+ int transactionID = program.startTransaction("TEST");
+
+ Function function =
+ createFunction(defaultName, address, new AddressSet(address, address.add(200L)));
+ assertNotNull("The test function was not created as expected.", function);
+
+ function.addTag("tag1");
+ function.addTag("tag2");
+ function.addTag("tag3");
+
+ DeleteFunctionCmd deleteFunctionCmd = new DeleteFunctionCmd(address);
+ deleteFunctionCmd.applyTo(program);
+
+ function = program.getListing().getFunctionAt(address);
+ assertNull("The function was not deleted as expected.", function);
+
+ program.endTransaction(transactionID, false);
+ }
+
// looks through the given symbol array to see if any have the same name
// as the provided string
private boolean containsMatchingSymbolName(Symbol[] symbols, String name) {
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 f4e7abea04..3e77ca4d6d 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 : function.getTags()) {
+ for (FunctionTag tag : new ArrayList<>(function.getTags())) {
function.removeTag(tag.getName());
}