Time-of-check to time-of-use: Difference between revisions

Content deleted Content added
revert - I was incorrect
Line 6:
 
In [[Unix]], the following [[C (programming language)|C]] code, when used in a [[setuid]] program, is a TOCTTOU bug:
<source lang="c">
if (access(file, R_OK) != 0) {
exit(1);
}
 
iffd (access= open(file, R_OKO_RDONLY) != 0) {;
// do something with fd...
exit(1);
</source>
}
fd = open(file, O_RDONLY);
// do something with fd...
 
Here, ''access'' is intended to check whether the real user who executed the setuid program would normally be allowed to read the file (i.e., ''access'' checks the [[real userid]] rather than [[effective userid]]).