Direct write into stack buffer may cause stack-based buffer overflow

ID

c.buffer_overflow.write_into_stack_buffer

Severity

low

Remediation Complexity

hard

Remediation Risk

high

Remediation Effort

medium

Resource

Buffer Overflow

Language

C / C++

Description

The software directly writes into a stack buffer. This might lead to a stack-based buffer overflow.

Rationale

The software directly writes into a stack buffer. This might lead to a stack-based buffer overflow.

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

void copy_string1(char *string)
{
	char buf[BUFSIZE];
	static char globuf[BUFSIZE];
	char *ptr;

	// VULNERABLE: Direct write into stack buffer may cause stack-based buffer overflow
	snprintf(buf, BUFSIZE, "%s", string);

	snprintf(globuf, BUFSIZE, "%s", string);

	ptr = (char *)malloc(BUFSIZE);

	snprintf(ptr, BUFSIZE, "%s", string);
}

Remediation

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

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved