Use of insecure sprintf/vsprintf functions prone to buffer overflow

ID

c.buffer_overflow.insecure_api_sprintf_vsprintf

Severity

critical

Resource

Buffer Overflow

Language

C / C++

Description

A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer.

Rationale

A buffer overflow condition exists when a program attempts to put more data in a buffer than it can hold, or when a program attempts to put data in a memory area outside of the boundaries of a buffer.

The following code illustrates a vulnerable pattern detected by this rule:

void copy_string(char *string, int number)
{
	char buf[BUFSIZE];
	char fmt[] = "whatever";

	// VULNERABLE: Use of insecure sprintf/vsprintf functions prone to buffer overflow
	sprintf(buf, "string: %s\n", string);

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.