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

Unbounded strcpy buffer overflow

highC/C++CWE-120CVSS 8.1

What it detects

strcpy copies without a length limit and can overflow the destination buffer.

How to fix

Use strncpy or strlcpy with an explicit bounded size and ensure null termination.

Vulnerable — Shield flags thiscopy.c
#include <string.h>

void save_username(const char *input) {
    char username[32];
    strcpy(username, input);
}
Fixed — scans cleancopy.c
#include <string.h>
#define USERNAME_MAX 32

void save_username(const char *input) {
    char username[USERNAME_MAX];
    strncpy(username, input, USERNAME_MAX - 1);
    username[USERNAME_MAX - 1] = '\0';
}

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

SHIELD-CPP-001: Unbounded strcpy buffer overflow — Zennoxa Shield