Skip to content

Use of deprecated function (gets)

Description

The gets() function reads a line from stdin into the provided buffer until either a terminating newline or EOF. This terminating newline or EOF is replaced with a null byte. No check for buffer overruns are performed so it is recommended to use fgets() instead. Do note that some platforms will continue reading data after a '\0' is encountered.

Examples

Insecure Code

c
gets(buffer);

Secure Code

c
fgets(buffer, sizeof(buffer), stdin);

Remediation

Replace gets() with fgets() for reading text-based input, or use read() or fread() for binary-based input.

Rule Details

FieldValue
IDCODE-0567
CategoryInjection
SeverityHIGH
CWECWE-120
ConfidenceHIGH
ImpactHIGH
LikelihoodHIGH
ExploitabilityEASY
Tagsbuffer overrun, deprecated function
OWASPA1:2017-Injection, A03:2021-Injection