Security
Patched Code Still Carries Hidden Security Risks, New Study Finds
Researchers show that supposedly "fixed" code remains semantically and structurally similar to vulnerable versions, leaving room for residual security flaws.
Software teams have long assumed that patching a vulnerability makes code safe, but a new arXiv research study challenges that assumption. Researchers analyzing real-world C/C++ code found that benign, patched functions often stay highly similar to their original vulnerable counterparts—a phenomenon they call "residual risk."
The Problem With Patch Validation#
Existing vulnerability benchmarks typically label patched code as secure and move on, but this overlooks a critical gap: whether a patch truly eliminates all traces of underlying risk. The team examined vulnerable-benign function pairs from PrimeVul, a dataset of production vulnerabilities, to test whether code-level similarity could predict lingering security weaknesses after patching.
Measuring Semantic and Structural Similarity#
The researchers deployed multiple code language models to measure how semantically alike patched and vulnerable functions remain, then cross-referenced this with abstract syntax tree (AST) analysis—a structural view of code. They combined these signals into a new metric called Residual Risk Scoring (RRS), which integrates embedding-based semantic similarity, localized AST-based structural similarity, and agreement across different models.
What They Discovered#
The findings were sobering:
- Benign functions retained strong semantic and structural resemblance to their vulnerable originals
- Approximately 61% of high-RRS code pairs exhibited 13 distinct categories of residual issues
- Common residual flaws included null pointer dereferences and unsafe memory allocation
- Static analysis tools (Cppcheck, Clang-Tidy, Facebook-Infer) validated these residual problems
Implications for Security Practice#
RRS provides a quantitative way to prioritize post-patch code inspection and validation. Rather than assuming patches are complete, security teams can use code similarity as a signal to flag patches that need deeper scrutiny. The work suggests that similarity-based risk assessment could strengthen software assurance practices and make patch validation more rigorous.

