# VNX-457: Use of Uninitialized Variable

Reports a C/C++ local scalar or char array declared without an initialiser whose first mention in the same block reads it (return v, v++, v += ..., a condition.

| Field | Value |
|---|---|
| Rule ID | `VNX-457` |
| Severity | Low |
| SARIF level | `note` |
| Kind | `sast` |
| Languages | C, C++ |
| CWE | [CWE-457](https://cwe.mitre.org/data/definitions/457.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 | `uninitialized` `cwe-457` |
| Source | [`internal/sast/rules/vnx-457.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-457.rego) |

## Overview

VNX-457 maps to [CWE-457: Use of Uninitialized Variable](https://cwe.mitre.org/data/definitions/457.html). It reports a function-local scalar (int, long, char, double, size_t, intN_t, bool...) declared without an initialiser, at its first mention within the next 25 lines of the same block, when that mention reads the value: `return v`, `v++`, a compound assignment, the right-hand side of an assignment, an if/while/switch condition, a printf-family argument or `std::cout << v`. A local char array is reported when its first use is strcat/strncat/strlen/strdup/puts or a printf argument. A first mention that assigns, takes the address (`&v`, scanf) or passes the variable to a call that may fill it is not reported, nor are static, namespace-scope and struct/class members.

## Why this matters

An uninitialised local holds whatever was on the stack. Accumulators start from garbage, status codes return stale values, and a string buffer without a terminator lets strcat walk off the end of the array.

## What gets flagged

```c
// FLAGGED: accumulator never zeroed
long total;
for (i = 0; i < n; i++) {
    total += samples[i];
}

// FLAGGED: buffer appended to before it holds a string
char path[256];
strcat(path, dir);

// NOT FLAGGED: assigned on every branch first
int r;
if (x > 100) r = 100; else r = x;
return r;
```

## Remediation

1. Initialise locals at the declaration (`long total = 0;`, `char path[256] = "";`).
2. Enable compiler warnings (`-Wall -Wuninitialized -Wmaybe-uninitialized`) and sanitizers (MSan) for the paths a line-oriented rule cannot follow.
3. For confirmed false positives, add a `// vulnetix-ignore: VNX-457` comment on the line.

## References

- [CWE-457: Use of Uninitialized Variable](https://cwe.mitre.org/data/definitions/457.html)
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)

## 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-457
// nosec vnx-457
```

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