🎄 Join our Annual Holiday wargame and win prizes!


Stack Buffer Overflow

Occurs when a program writes more data to a stack-allocated buffer than the buffer can hold, leading to the overflow of adjacent memory regions. This overflow into adjacent memory locations can lead to overwriting other data, corrupting the program's execution, and leading to security vulnerabilities or crashes.

A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function).

"Stack Overflow" is often used to mean the same thing as stack-based buffer overflow, however it is also used on occasion to mean stack exhaustion, usually a result from an excessively recursive function call. Due to the ambiguity of the term, use of stack overflow to describe either circumstance is discouraged.

Remediation:

  • Implement and perform bounds checking on input.
  • Do not use dangerous functions such as gets. Use safer, equivalent functions which check for boundary errors.

Metadata

  • Severity: high
  • Slug: buffer-overflow

CWEs

  • 121: Stack-based Buffer Overflow

Available Labs

Open C labs in SecDim Play for this vulnerability.

Deco line
Deco line

Play AppSec WarGames

Want to skill-up in secure coding and AppSec? Try SecDim Wargames to learn how to find, hack and fix security vulnerabilities inspired by real-world incidents.

Deco line
Deco line

Got a comment?

Join our secure coding and AppSec community. A discussion board to share and discuss all aspects of secure programming, AppSec, DevSecOps, fuzzing, cloudsec, AIsec code review, and more.

Read more