Skip to content

Commit

Permalink
os: update TOCTOU example in readme, to improve readability of the mo…
Browse files Browse the repository at this point in the history
…dule docs on mobile (#19255)
  • Loading branch information
ttytm committed Sep 1, 2023
1 parent 448f604 commit 0450a93
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions vlib/os/README.md
Expand Up @@ -23,28 +23,32 @@ so that <b>TOCTOU</b> is no longer possible.

<table>
<tr>
<td>Possibility for TOCTOU attack</td>
<td>TOCTOU not possible</td>
</tr>
<tr>
<td>
Possibility for TOCTOU attack

```v ignore
if os.is_writable("file"){

// >> time to make a quick attack (e.g. symlink /etc/passwd to >file<) <<
```v ignore
if os.is_writable("file") {
// time to make a quick attack
// (e.g. symlink /etc/passwd to `file`)
mut f := os.create('path/to/file') ?
// <do something with file>
mut f := os.create('path/to/file')!
// do something with file
f.close()
}
```
</td>
<td>TOCTOU not possible
<td>

```v ignore
mut f := os.create('path/to/file') or {
println("file not writable")
}
// >> do something with file; file is locked <<
// file is locked
// do something with file
f.close()
```
Expand Down

0 comments on commit 0450a93

Please sign in to comment.