...
Compliant Solution (Linux 2.1.126+, FreeBSD, Solaris 10, POSIX.1-2008 O_NOFOLLOW)
Some systems provide the O_NOFOLLOW flag to help mitigate this problem. The flag will be required by the forthcoming POSIX.1-2008 standard, and so will become more portable over time \[ [Austin Group 2008|AA. Bibliography#Austin Group 08]\]. If the flag is set and the supplied {{Wiki Markup file_name}} is a symbolic link, then the open will fail.
| Code Block | ||||
|---|---|---|---|---|
| ||||
char *file_name = /* something */;
char *userbuf = /* something */;
unsigned int userlen = /* length of userbuf string */;
int fd = open(file_name, O_RDWR | O_NOFOLLOW);
if (fd == -1) {
/* handle error */
}
write(fd, userbuf, userlen);
|
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
POS01-C | medium | likely | high | P6 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||
|---|---|---|---|---|---|---|---|
|
|
|
|
...
MITRE CWE: CWE-367, "Time-of-check Time-of-use (TOCTOU) Race Condition"
Bibliography
\[[Austin Group 2008|AA. Bibliography#Austin Group 08]\]
\[[Open Group 2004|AA. Bibliography#Open Group 04]\] [{{open()}}|http://www.opengroup.org/onlinepubs/009695399/functions/open.html]
\[[Seacord 2005|AA. Bibliography#Seacord 05]\] Chapter 7, "File ]Wiki Markup
[Open Group 2004] open()
[Seacord 2005] Chapter 7, "File I/O"
...