# VNX-587: Assignment of a Fixed Address to a Pointer

Reports an integer literal of 0x1000 or above cast to a pointer and assigned, returned or bound by #define in C and C++. Null and sentinel values.

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

## Overview

VNX-587 maps to [CWE-587: Assignment of a Fixed Address to a Pointer](https://cwe.mitre.org/data/definitions/587.html). It reports a cast of an integer literal to a pointer type (C casts and `reinterpret_cast`) that is assigned to a pointer, returned, or bound by a `#define`, including a cast whose literal is on the next line.

## Why this matters

A hard-coded address ties the program to one memory layout. When the layout changes (another board revision, ASLR, a different loader), the pointer refers to unrelated or unmapped memory, which corrupts data or crashes, and a predictable address helps an attacker.

## What gets flagged

```c
int *p = (int *)0x8000;
reg = (uint8_t *)0xFFFF0000u;
#define UART0_DR (*(volatile unsigned int *)0x4000C000)
```

```cpp
auto *ctrl = reinterpret_cast<std::uint32_t *>(0x1F000000);
```

Not flagged: `(void *)0`, `(char *)-1`, `(void *)0x100` and other values below the first page, `0xFFFFFFFF`, poison values such as `0xdeadbeef`, `(uintptr_t)0x40020000`, `(uint32_t *)(base + 0x4000)`, `child == (void *)0x40020000`, casts passed as arguments, comments, strings and test files.

## Remediation

1. Take device addresses from the platform's headers, linker map or device tree rather than literals scattered through the code.
2. On hosted systems, obtain memory from `mmap()` or the allocator and never assume an absolute address.

## References

- [CWE-587: Assignment of a Fixed Address to a Pointer](https://cwe.mitre.org/data/definitions/587.html)

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

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