Commit bd60432
Fix TOCTOU race condition in cache_key.c
Use open() with O_CREAT|O_EXCL|O_NOFOLLOW and mode 0600 instead of
fopen() to create the temp file. This prevents:
- Symlink attacks (O_NOFOLLOW)
- Race conditions where attacker pre-creates the file (O_EXCL)
- Permissions set at creation time, not after (mode 0600)
Then use fdopen() to get a FILE* for fprintf().
Also check fclose() return value to catch flush errors (ENOSPC, NFS)
that would otherwise result in a truncated file being renamed.
Reported by CodeQL, improved based on Copilot review.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent 8daf677 commit bd60432
1 file changed
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
119 | 130 | | |
| 131 | + | |
| 132 | + | |
120 | 133 | | |
121 | 134 | | |
122 | 135 | | |
| |||
125 | 138 | | |
126 | 139 | | |
127 | 140 | | |
128 | | - | |
129 | 141 | | |
130 | | - | |
131 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
132 | 147 | | |
133 | 148 | | |
134 | 149 | | |
| |||
0 commit comments