Blog

Can LLMs fix memory bugs?

We tested ten LLMs with SecureMind. The best at repair, o1, fixed 37.1%, and none fixed a bug that spans several functions. Detection was easily thrown off by a variable name.

The Chromium team found that 70% of their most serious security bugs are memory bugs: out-of-bounds reads and writes, use-after-free, double free, null pointers. They are most common in C and C++, and the hardest to track down.

Plenty of teams now ask LLMs to find these bugs and write the patches. How do you know whether the model is any good at it?

How it is measured today

Most existing benchmarks are hand-written test cases, or problems like programming contests and coursework, which look little like bugs in real projects. Worse, there is leakage. Public bugs and their patches may well be in the model’s training data, which inflates the score.

SecureMind

SecureMind, from our ISMM 2025 paper, is an open-source framework; the code is on GitHub. You write a test plan of a few dozen lines naming the model and its training cutoff, and it does the rest:

  • Collects CVEs from six sources, including NVD and GitHub advisories, and keeps only those published after the model’s cutoff, so it can’t have memorized them.
  • Pulls the vulnerable function and its fixed version from each fix commit, and mixes them for the model to judge.
  • Rewrites the code in 14 ways, such as renaming, dead code and misleading comments, to see whether the model can be thrown off.
  • Checks each patch with CodeQL for whether the bug is gone and nothing new was introduced, then compiles it and runs the project’s own tests.

What we found

37.1%repair success of the best model, o1

3.3%the lowest, Qwen2.5-7B

0 / 9bugs that span several functions

We tested ten models, among them o1, GPT-4o, DeepSeek-R1, DeepSeek-V3, Gemini and Llama, on eight kinds of memory bug. It took over 5,000 CPU hours and more than 10 billion tokens.

Repair is the weakest link. Each bug got ten attempts and counted as fixed if any passed the tests. The best model, o1, fixed 37.1%; the worst, 3.3%. Nine bugs needed changes to several functions, and even with all the relevant code in front of them, no model fixed any. More often, a model found the right spot and then wrote a wrong patch.

Detection is easy to mislead. Wrap gets() in a macro called safe_input and Gemini 2.0 Flash calls it safe. Add one unrelated line and Llama 3.3 70B misses a use-after-free. One case stuck with us: a double free that had already been fixed, the same prompt, temperature 0, and GPT-4o called it vulnerable in one run out of ten.

There is good news too. On 76 CVEs in the Linux kernel, GPT-4o found 41 and CodeQL found 6. Its reasons were not always right, though; sometimes the verdict was correct and the explanation wrong.

Where we land

LLMs can already help find bugs. Handing them the fix is another matter. They need more context, an environment where code really compiles and tests really run, and someone or something to check their conclusions. That is part of why we went on to build verifiable coding agents.

The study has limits. Repair rests on 23 real bugs for which we could get the official patch and tests, which is a small sample. And models move fast; these numbers describe the versions we tested.

Paper · ISMM 2025SecureMind: A Framework for Benchmarking Large Language Models in Memory Bug Detection and Repair

BLOG

More posts

Next step

AI that understands how code runs.

Contact