Skip to content

Insecure use of gets() function

Description

The gets() function is always unsafe because it does not perform bounds checking on the size of its input. An attacker can easily send arbitrarily-sized input to gets() and overflow the destination buffer.

Examples

Insecure Code

c
char buffer[10]; gets(buffer);

Secure Code

c
char buffer[10]; fgets(buffer, 10, stdin);

Remediation

Replace gets() with fgets() to perform bounds checking on input size

Rule Details

FieldValue
IDCODE-0280
CategoryInjection
SeverityCRITICAL
CWECWE-120
ConfidenceHIGH
ImpactHIGH
LikelihoodHIGH
ExploitabilityEASY
Tagsbuffer overflow, input validation
OWASPN/A

References