Skip to content

Usage of deprecated function (cuserid)

Description

The `cuserid()` function is poorly defined and can't be trusted. It was removed from POSIX in 1990 and has a risk of buffer overflow if the passed-in buffer is not at least `L_cuserid` characters long. Instead, use `getpwuid(geteuid())` and extract the desired information.

Examples

Insecure Code

c
char *user = cuserid(NULL);

Secure Code

c
struct passwd *pw = getpwuid(geteuid()); char *user = pw->pw_name;

Remediation

Replace `cuserid()` with `getpwuid(geteuid())` and extract the desired information.

Rule Details

FieldValue
IDCODE-0599
CategoryInsecureConfig
SeverityLOW
CWECWE-120
ConfidenceHIGH
ImpactLOW
LikelihoodLOW
ExploitabilityCOMPLEX
Tagsdeprecated function, buffer overflow
OWASPA9:2017-Using Components with Known Vulnerabilities, A06:2021-Vulnerable and Outdated Components