# VNX-685: Function Call With Incorrect Number of Arguments

Detects C and C++ printf- and scanf-family calls whose literal format asks for a different number of arguments than are passed.

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

## Overview

VNX-685 maps to [CWE-685: Function Call With Incorrect Number of Arguments](https://cwe.mitre.org/data/definitions/685.html). Variadic functions cannot check their argument count. A printf with too few arguments reads whatever is on the stack (a disclosure, or a crash on `%s`); a scanf with too few pointers writes through a garbage one; `open()` with `O_CREAT` and no mode creates a file with indeterminate permissions.

## What gets flagged

```c
printf("user %s failed with %d\n", user);      // FLAGGED: %d has no argument
fprintf(log, "%s\n", user, code);              // FLAGGED: one argument too many
scanf("%d %d", &a);                            // FLAGGED: second %d writes through garbage
if (sscanf(line, "%d:%s", &a) != 2) {          // FLAGGED
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC);   // FLAGGED: no mode
asprintf(&s, "%s:%d", path);                   // FLAGGED
err(1, "cannot label %s (%d)", path);          // FLAGGED
fprintf(stderr, "%s: %d of %d\n",              // FLAGGED: call continues below
        name, a);
```

printf, fprintf, sprintf, snprintf, dprintf, asprintf, syslog and err/errx/warn/warnx count `*` width and precision as arguments; scanf, fscanf and sscanf count `%[...]` sets and `%n` but not `%*` suppressed conversions.

## What is not flagged

- Calls still open after three continuation lines, formats built from macros such as `PRIu64`, and positional `%1$s` conversions.
- Project wrappers (`my_printf`, logging macros), whose conventions are unknown.
- `open()` with a mode, or without `O_CREAT`.
- Comments and string literals.

VNX-628 also reports the printf and `open()` shapes.

## Remediation

Compile with `-Wall -Wformat=2` and fix every warning; pass the mode whenever `O_CREAT` is set: `open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600)`.

## References

- [CWE-685: Function Call With Incorrect Number of Arguments](https://cwe.mitre.org/data/definitions/685.html)
- [SEI CERT FIO47-C: Use valid format strings](https://wiki.sei.cmu.edu/confluence/display/c/FIO47-C.+Use+valid+format+strings)

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

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