CWE-1119 is code that uses too many unconditional branches, such as goto. MITRE marks it as a quality issue with no direct security implications and prohibits mapping real vulnerabilities to it.
The word that matters is excessive. A single, disciplined goto cleanup is a common and accepted pattern in C. The weakness is a function that jumps in many directions.
How it happens
A function grows by patches. Each new error case adds a jump to a label somewhere else, and soon the order of execution has to be traced with a finger. Cleanup labels are reused for cases they were never designed for.
What an attacker gains
Nothing directly. MITRE lists reduced maintainability and increased analytical complexity, noting that the issue makes the product harder to understand and maintain, which indirectly makes vulnerabilities more time-consuming to find and fix and might make them easier to introduce.
A related real-world case appears elsewhere in the CWE list. The widely known goto fail bug, CVE-2014-1266, is described by MITRE as an incorrect goto in Apple's SSL product that bypassed certificate validation. It is recorded against other weaknesses, not this one, but it shows how a stray jump can skip a security check.
How to find it
The record lists no detection methods. Count goto statements per function, look for labels that are targeted from many places, and watch for jumps that go backwards or into the middle of other logic.
How to fix it
The record has no formal mitigations. Common restructuring choices:
- Replace jump-based flow with structured loops and early returns.
- Where cleanup is needed, use one clearly named cleanup label at the end of the function, or language features built for it, such as
defer,finally, context managers or RAII. - Split long functions into smaller ones so each has a short, readable flow.
- Always use braces on conditionals so a jump cannot slip out of its intended scope.
Quick check
Is goto always wrong?
No. A single forward jump to a shared cleanup block is a widely used pattern. The weakness is excessive use.