Memory Safety Roadmaps for Legacy C and C++ Systems: Where Government Programs Should Start
How to build a memory safety roadmap for a legacy government system: inventory components and dependencies, pick harden, isolate, or replace per component, and verify behavior after each migration step.
Much of the software that runs government and defense missions was written in C and C++ decades ago, and most of it will still be running at the end of this decade. Federal guidance now asks software producers to publish plans for reducing memory safety vulnerabilities in exactly this kind of code. The hard part for a program office is deciding where to begin, and how to show that each step improved security without changing behavior.
This post lays out a component-by-component approach: inventory first, then one of three treatments per component, then verification that produces evidence a reviewer can check.
What the guidance asks for
In January 2025, the Cybersecurity and Infrastructure Security Agency (CISA) and the Federal Bureau of Investigation (FBI) published version 2.0 of Product Security Bad Practices. It states that for existing products written in memory-unsafe languages, not having a published memory safety roadmap is “dangerous and significantly elevates risk,” and it recommended that manufacturers publish one by the end of 2025. The roadmap should describe a prioritized approach to removing memory safety vulnerabilities from priority components, with network-facing code and cryptographic code given as examples. Products with an announced end-of-support date before January 1, 2030 are exempt. The document is non-binding.
In June 2025, CISA and the National Security Agency (NSA) followed with a joint guide, Memory Safe Languages: Reducing Vulnerabilities in Modern Software Development, which identifies the main obstacles to adoption and covers language-level protections, library support, tooling, and developer training. Press coverage quoted the guide’s own caution that memory safe languages “are not a panacea” and that the transition is hardest “for organizations with large existing codebases or mission-critical systems.”
The guidance is aimed at commercial software manufacturers, so it does not bind a government-owned system built under contract. It is still the clearest template for a credible plan, and the systems that need one are easy to find. The Government Accountability Office’s July 2025 report GAO-25-107795 examined the 11 federal legacy systems most in need of modernization: they are 23 to 60 years old, eight use outdated languages, and seven run with known cybersecurity vulnerabilities.
Why the whole system does not need to move at once
The strongest public evidence that incremental migration works comes from Android. In a September 2024 post, Google reported that memory safety issues fell from 76 percent of Android vulnerabilities in 2019 to 24 percent in 2024. Google credits a policy of writing new code in memory-safe languages while leaving most existing code alone, and said it would focus on interoperability rather than rewriting the memory-unsafe code it already has.
This works because vulnerabilities concentrate in new or recently modified code, while old code that nobody touches stops producing new defects at the same rate. For a legacy program, that turns a daunting rewrite into a prioritization problem: treat first the components that face untrusted input, change often, or would hurt most if compromised. A stable module that has not changed since 2009 can wait.
Start with a component and dependency inventory
A roadmap built on a guess about what the codebase contains will not survive its first review. For each component, establish:
- Language and build. Which compiler and version produce it, and which hardening flags the build already uses.
- Exposure. Whether it reads network traffic, external files, or user-controlled input, directly or through another component.
- Change rate. How often it has been modified in recent years, and whether planned work will touch it again.
- Dependencies. Which third-party and open source libraries it links, including transitive ones, and whether any are written in C or C++ and past vendor support.
- Behavior contracts. Which outputs, side effects, and error behaviors other systems depend on, so a replacement can be checked against them.
The dependency item matters more than it looks. A component rewritten in a memory-safe language still inherits the exposure of every C library it calls across a foreign function interface, so a roadmap that moves application code but keeps a 15-year-old parsing library underneath has relocated the risk. Our post on behavior preservation in legacy code modernization describes how to extract the contracts in item five with file and line evidence.
Three treatments, chosen per component
Each component then gets one of three treatments, depending on exposure, change rate, and how well its behavior is understood.
| Treatment | What it involves | What it buys | What it does not do |
|---|---|---|---|
| Harden in place | Modern compiler flags, bounds-checked library variants, sanitizers and fuzzing in test | Fewer exploitable defects at low cost, no behavior change | Does not make C or C++ memory safe |
| Isolate | Narrow interface, reduced privileges, input validation before data reaches the component | Limits what a defect can reach; buys time for stable code | Does not fix the defects; adds an interface that must be tested |
| Replace | Rewrite or translate into a memory-safe language behind the same interface | Removes the vulnerability class from that component | Introduces new code, where defects concentrate; needs behavioral verification |
Hardening is the default for everything, because it costs little and changes nothing observable. Isolation suits components that are exposed but stable. Replacement is reserved for components that are exposed, change often, or carry the most sensitive paths: it is the only treatment that removes the problem, and the only one that creates new behavior to verify.
Automated translation is becoming a realistic option for that third treatment. The Defense Advanced Research Projects Agency’s TRACTOR program (Translating All C to Rust) combines static and dynamic analysis with large language models, aiming for Rust of “the same quality and style that a skilled Rust developer would produce,” with test and evaluation by MIT Lincoln Laboratory. It is research, not a product, and its framing carries the right lesson: translation output is a draft until it has been evaluated.
Verification after migration
A replaced component is a change to a mission system like any other. Three checks separate a rewrite that is believed to work from one that is shown to work.
- Characterization tests captured from the legacy component, with expected outputs recorded by running the old code, not predicted by a model or a developer.
- Differential testing that runs the old and new implementations on the same inputs, including a fuzzing corpus, and compares outputs and side effects. Any divergence is either an approved change or a defect.
- Unsafe surface review of the new code: how many escape hatches into unchecked memory access it contains, where they are, and why each is needed. A translation that preserves every raw pointer has changed syntax, not safety.
These results are also the evidence an authorizing official will ask for at change review, a connection we covered in federal legacy IT modernization and the ATO. Evidence per component lets the roadmap be updated with facts: which components have been treated, how, and with what residual risk.
An illustrative example
Consider a 1990s logistics messaging service written in C, with illustrative numbers. The inventory finds 38 components. Four parse messages that arrive from partner systems over the network. Two of those four were modified in the last year to support a new message format, and one links a compression library that reached end of support in 2019.
The roadmap that follows is short. All 38 components get hardened builds and fuzzing in test. The two recently changed network parsers are replaced first, with the compression library swapped for a maintained alternative at the same time, since rewriting the parser on top of the old library would leave its exposure in place. The other two parsers are isolated behind input validation and a reduced-privilege process, and revisited once the first replacements have a verified record. The remaining 32 components are hardened and left alone, with their change rate monitored.
The numbers are invented, but the shape is typical. A small fraction of the code carries most of the exposure, and the roadmap’s credibility comes from naming which fraction and why.
How QuantumWorks approaches this
PRISM is built for the inventory and verification steps. Its analyzers generate a Behavior Specification Graph from a legacy codebase: entry points, contracts, dependencies, must-preserve paths, and risk signals, each anchored to file and line. Proposed transformations pass compile, test, differential behavior, and static analysis gates, and none is committed without human approval. Cryptographic code is one of the priority component classes the guidance names, and Sentinel helps organizations understand and change cryptography across many systems at once, so a memory safety roadmap and a post-quantum migration plan can draw on the same inventory. CAM provides asset-level cryptographic evidence for assets in production after migration.
If your program needs a memory safety roadmap for a legacy system, or needs to show that a migrated component still does what the old one did, we would be glad to talk. Contact QuantumWorks.