{"record":{"id":"4ce2562a85391b30","repo":"NationalSecurityAgency/ghidra","slug":"return-address-must-be-in-4ce256","errorCode":null,"errorMessage":"Return address must be in {}","messagePattern":"Return address must be in (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/AnalysisUnwoundFrame.java","lineNumber":163,"sourceCode":"\t@Override\n\tprotected SavedRegisterMap computeRegisterMap() {\n\t\treturn registerMap;\n\t}\n\n\t@Override\n\tprotected Address computeAddressOfReturnAddress() {\n\t\treturn info.ofReturn(base);\n\t}\n\n\t@Override\n\tpublic Address getReturnAddress() {\n\t\treturn info.computeNextPc(base, state, codeSpace, pc);\n\t}\n\n\t@Override\n\tpublic CompletableFuture<Void> setReturnAddress(StateEditor editor, Address addr) {\n\t\tif (addr.getAddressSpace() != codeSpace) {\n\t\t\tthrow new IllegalArgumentException(\"Return address must be in \" + codeSpace);\n\t\t}\n\t\tBytesPcodeArithmetic bytesArithmetic = BytesPcodeArithmetic.forLanguage(language);\n\t\tbyte[] bytes = bytesArithmetic.fromConst(addr.getOffset(), pc.getNumBytes());\n\t\treturn editor.setVariable(info.ofReturn(base), bytes);\n\t}\n\n\t@Override\n\tpublic int getLevel() {\n\t\treturn level;\n\t}\n\n\t@Override\n\tpublic String getDescription() {\n\t\treturn String.format(\"%s %s pc=%s sp=%s base=%s\", level, info.function(),\n\t\t\tpcVal == null ? null : pcVal.toString(false),\n\t\t\tspVal == null ? null : spVal.toString(false),\n\t\t\tbase == null ? null : base.toString(false));\n\t}","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/AnalysisUnwoundFrame.java#L145-L181","documentation":"AnalysisUnwoundFrame.setReturnAddress() mirrors the abstract one: it writes the given address to the return-address location (info.ofReturn(base)). It requires addr.getAddressSpace() == codeSpace; any other space throws IllegalArgumentException(\"Return address must be in \" + codeSpace). The PC must be written into the executable code space.","triggerScenarios":"Calling setReturnAddress with an address not in the frame's code space (stack, register, constant, external). Passing a return address derived from a different language's space layout.","commonSituations":"Setting a return address from a script using the wrong address space. Misidentifying the return storage as a stack slot. Languages with separate code/data spaces.","solutions":["Ensure the address is in the code space: check addr.getAddressSpace().equals(codeSpace) before calling.","Resolve any raw offset into the code space of the frame's language first.","Use a different API if the target is genuinely not a code address."],"exampleFix":"// before\nframe.setReturnAddress(editor, addrFromWrongSpace); // throws\n\n// after\nif (addr.getAddressSpace().equals(codeSpace)) {\n    frame.setReturnAddress(editor, addr);\n} else {\n    throw new IllegalArgumentException(\"return address not in code space: \" + addr);\n}","handlingStrategy":"validation","validationCode":"if (!addr.getAddressSpace().equals(codeSpace)) {\n    throw new IllegalArgumentException(\"return address must be in code space \" + codeSpace);\n}\nframe.setReturnAddress(editor, addr);","typeGuard":"public static boolean isInCodeSpace(Address addr, AddressSpace codeSpace) {\n    return addr != null && codeSpace != null && addr.getAddressSpace().equals(codeSpace);\n}","tryCatchPattern":"try {\n    frame.setReturnAddress(editor, addr);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Return address must be in\")) {\n        addr = codeSpace.getAddress(addr.getOffset());\n        frame.setReturnAddress(editor, addr);\n    } else throw e;\n}","preventionTips":["Pass only code-space addresses to setReturnAddress.","Resolve offsets into the frame's code space first.","Validate address space against the frame's language before writing the PC."],"tags":["stack-unwinding","validation","address-space","registers"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}