# VNX-1265: Unintended Reentrant Invocation of Non-reentrant Code Via Nested Calls

strtok() keeps its position in hidden static state, so it is not reentrant: starting a second tokenization while one is in progress silently replaces the first.

| Field | Value |
|---|---|
| Rule ID | `VNX-1265` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | C |
| CWE | [CWE-1265](https://cwe.mitre.org/data/definitions/1265.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:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `unintended-reentrant` `strtok` `c` `cwe-1265` |
| Source | [`internal/sast/rules/vnx-1265.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1265.rego) |

## Overview

VNX-1265 maps to [CWE-1265: Unintended Reentrant Invocation of Non-reentrant Code Via Nested Calls](https://cwe.mitre.org/data/definitions/1265.html).

## Why this matters

`strtok()` stores its position in hidden static state. When a loop that is tokenizing one string calls `strtok()` on another string, directly or through a helper, the inner call replaces that state. The outer loop's next `strtok(NULL, ...)` then continues through the wrong buffer or stops early, so input is skipped or misparsed.

## What gets flagged

```c
char *item = strtok(line, ";");
while (item != NULL) {
    parse_pair(item, &key, &value);   /* parse_pair() calls strtok(pair, "=") */
    item = strtok(NULL, ";");
}

for (row = strtok(text, "\n"); row; row = strtok(NULL, "\n")) {
    cell = strtok(row, ",");          /* nested tokenization */
}
```

Not flagged: `strtok_r()`, a second tokenization that starts after the first loop has ended, helpers that do not call `strtok()`.

## Remediation

1. Use `strtok_r()` (POSIX) or `strtok_s()` with a separate save pointer for each tokenization.
2. Signal handlers that call non-reentrant functions are reported separately by VNX-479 and VNX-828.

## References

- [CWE-1265: Unintended Reentrant Invocation of Non-reentrant Code Via Nested Calls](https://cwe.mitre.org/data/definitions/1265.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-1265
// nosec vnx-1265
```

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