# VNX-1119: Excessive Use of Unconditional Branching

Reports a backward goto in C++: a goto whose label is defined earlier in the same function.

| Field | Value |
|---|---|
| Rule ID | `VNX-1119` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | C++ |
| CWE | [CWE-1119](https://cwe.mitre.org/data/definitions/1119.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:L/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:L/DI:H/EX:L/EC:N/P:L` |
| Tags | `excessive-unconditional-branching` `cwe-1119` `maintainability` `c` `cpp` |
| Source | [`internal/sast/rules/vnx-1119.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1119.rego) |

## Overview

VNX-1119 maps to [CWE-1119: Excessive Use of Unconditional Branching](https://cwe.mitre.org/data/definitions/1119.html). It reports a `goto label;` in a C++ file (`.cc`, `.cpp`, `.cxx`, `.hpp`, `.hh`) whose label is defined **above** it in the same function: a loop (`retry`, `again`, `restart`, `top`) written with unconditional jumps instead of `while`, `for` or `do`. A retry that reaches its label through a forward jump to an error handler is reported too.

The same backward goto in a C file (`.c`, `.h`) is reported by [VNX-1075](/sast/rules/vnx-1075.md), so one jump is one finding.

Not reported:

- forward gotos to a cleanup or error label (`goto out;`, `goto err;`, `goto cleanup;`), the idiomatic error-unwinding pattern;
- a backward goto between chained error handlers whose target ends in `return`, so control never comes back round;
- a label of the same name in an earlier function, computed gotos (`goto *ptr`), and gotos in comments (including a `/* */` block whose lines carry no leading `*`) or strings;
- C files, which [VNX-1075](/sast/rules/vnx-1075.md) covers.

## Why this matters

Backward jumps are what make goto-heavy code hard to reason about. A retry loop written with `goto` has no visible bound, so it is easy to loop forever on a persistent error, or to jump back over an initialisation and re-enter with stale state (a freed buffer, a closed descriptor).

## What gets flagged

```cpp
int Parser::next()
{
again:
    int c = in_.get();
    if (c == ' ')
        goto again;          // FLAGGED: backward goto
    return c;
}
```

```cpp
    if (!buf)
        goto cleanup;        // NOT FLAGGED: forward jump to cleanup
    ...
cleanup:
    delete[] buf;
```

## Remediation

1. Rewrite the backward jump as a `do { ... } while (cond);` or `for` loop with an explicit retry bound.
2. Keep `goto` for forward jumps to a single cleanup path, or replace it with RAII so the cleanup runs on every exit.

## References

- [CWE-1119: Excessive Use of Unconditional Branching](https://cwe.mitre.org/data/definitions/1119.html)
- [SEI CERT C: MEM12-C. Consider using a goto chain when leaving a function on error](https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-1119
// nosec vnx-1119
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-1119 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
