# VNX-466: Return of Pointer Value Outside of Expected Range

Reports a C/C++ function that returns a pointer offset from an unchecked strchr/strrchr/memchr/strstr/strpbrk result (return strchr(s, '=') + 1.

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

## Overview

VNX-466 maps to [CWE-466: Return of Pointer Value Outside of Expected Range](https://cwe.mitre.org/data/definitions/466.html). Reports a C/C++ function that returns a pointer offset from an unchecked strchr/strrchr/memchr/strstr/strpbrk result (return strchr(s, '=') + 1, or p = strchr(...) then return p + 2 with no NULL test), which yields NULL + n when the search fails.

## Why this matters

This weakness class (Return of Pointer Value Outside of Expected Range) creates a concrete exploit surface: the rule searches for the concrete source-level patterns most commonly associated with CWE-466 and surfaces them for review. Each finding should be evaluated in context, the rule catches the pattern, not the context.

## What gets flagged

```c
// FLAGGED: offset added to a search that can return NULL
return strchr(entry, '=') + 1;

// FLAGGED: two-line form, no NULL test before the return
char *p = strchr(reply + 1, '\r');
return p + 2;

// NOT FLAGGED: the result is checked first
const char *p = strrchr(s, ':');
if (!p) return s;
return p + 1;
```

## Remediation

1. Review each flagged line and determine whether the pattern represents a real instance of CWE-466 or a false positive.
2. Replace the flagged construct with a documented safe alternative appropriate to your language and framework.
3. For confirmed false positives, add a `# vulnetix-ignore: VNX-466` comment on the line.
4. Ensure equivalent test coverage exists to prevent regression.

## References

- [CWE-466: Return of Pointer Value Outside of Expected Range](https://cwe.mitre.org/data/definitions/466.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-466
// nosec vnx-466
```

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