Buffer Overflow
Overview
Buffer overflows occur when data is written beyond the boundaries of allocated memory. In C/C++, unsafe library functions have no bounds checking:
gets(): Reads unlimited input into fixed buffer — deprecated and removed from C11strcpy(): Copies until null terminator with no size limitstrcat(): Concatenates with no size limitsprintf(): Formats with no output buffer size check
Consequences: Stack corruption, return address overwrite, arbitrary code execution, privilege escalation.
Remediation
Replace unsafe functions with safe alternatives:
gets()→fgets(buf, sizeof(buf), stdin)orgetline()strcpy()→strncpy()+ manual null termination, orstrlcpy()strcat()→strncat()orstrlcat()sprintf()→snprintf(buf, sizeof(buf), ...)