Commit de5c38c
committed
CA-208547: Avoid races in pointing stdin/stdout/stderr at /dev/null
The two calls to Unix.dup are intended to point stdout and stderr at
/dev/null - this will normally be the case, as Unix.dup will open the
next available file descriptor and stdout/stderr have just been closed.
However, there are many ways this can go wrong - if an open() happens
in another thread it could mean that...
* nullfd <> Unix.stdin - this is checked for, but there is no error
handling if this fails
* one or both of the Unix.dup calls do not point stdout/stderr at
/dev/null as intended, but instead open new file descriptors.
This change instead uses Unix.dup2 which atomically closes the second
file descriptor and copies it from the first. This also allows the
explicit calls to Unix.close to be removed. Finally, nullfd is closed as
it is not needed after the calls to Unix.dup2.
Signed-off-by: John Else <[email protected]>1 parent e977fa9 commit de5c38c
1 file changed
+4
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | 557 | | |
561 | | - | |
562 | | - | |
563 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
564 | 562 | | |
565 | 563 | | |
566 | 564 | | |
| |||
0 commit comments