Zennoxa Shield
Rules / C/C++
SHIELD-CPP-007

Non-constant format string with stream target

highC/C++CWE-134CVSS 8.6

What it detects

fprintf or sprintf using a variable as the format argument enables format string attacks.

How to fix

Pass an explicit constant format string instead of a variable.

Vulnerable — Shield flags thiswarn.c
#include <stdio.h>

void warn(const char *msg) {
    fprintf(stderr, msg);
}
Fixed — scans cleanwarn.c
#include <stdio.h>

void warn(const char *msg) {
    fprintf(stderr, "%s", msg);
}

Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-CPP-007, the fixed one does not.

SHIELD-CPP-007: Non-constant format string with stream target — Zennoxa Shield