Rules / C/C++
SHIELD-CPP-002
Unbounded strcat buffer overflow
What it detects
strcat appends without checking remaining destination capacity.
How to fix
Use strncat or strlcat with the remaining buffer size accounted for.
Vulnerable — Shield flags thisappend.c
#include <string.h>
void build_greeting(char *msg, const char *name) {
strcat(msg, name);
}
Fixed — scans cleanappend.c
#include <string.h>
void build_greeting(char msg[64], const char *name) {
strncat(msg, name, 64 - strlen(msg) - 1);
}
Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-CPP-002, the fixed one does not.