Skip to content

Potential time of check time of use vulnerability (tmpfile)

Description

There exists a possible race condition in between the time that `tmpfile` returns a pathname, and the time that the program opens it, another program might create that pathname using `open`, or create it as a symbolic link. Consider using the `mkstemp` function instead, but be aware it also contains possible risks. Ensure the process has called the `umask` function with restricted permissions prior to calling `mkstemp` and validate the permissions prior to using the file descriptor.

Examples

Insecure Code

c
FILE *fp = tmpfile();

Secure Code

c
int fd = mkstemp(template); if (fd == -1) { /* handle error */ }

Remediation

Use `mkstemp` instead of `tmpfile` and ensure proper permissions are set with `umask`

Rule Details

FieldValue
IDCODE-0619
CategoryInsecureConfig
SeverityMEDIUM
CWECWE-377
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagstime of check time of use, race condition
OWASPA5:2017-Broken Access Control, A01:2021-Broken Access Control