Skip to content

Commit

Permalink
Fixed a null dereference bug (#57)
Browse files Browse the repository at this point in the history
Removed redundant close we want the 0 fd to be taken so we 
can dup2 into it without race with open from another thread.
  • Loading branch information
barp authored and sevlyar committed May 4, 2019
1 parent dcccaf7 commit 1c1036e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions daemon_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func (d *Context) child() (err error) {

decoder := json.NewDecoder(os.Stdin)
if err = decoder.Decode(d); err != nil {
d.pidFile.Remove()
return
}

Expand All @@ -226,14 +225,14 @@ func (d *Context) child() (err error) {
if err = d.pidFile.WritePid(); err != nil {
return
}
defer func() {
if err != nil {
d.pidFile.Remove()
}
}()
}

if err = syscall.Close(0); err != nil {
d.pidFile.Remove()
return
}
if err = syscallDup(3, 0); err != nil {
d.pidFile.Remove()
return
}

Expand All @@ -243,7 +242,6 @@ func (d *Context) child() (err error) {
if len(d.Chroot) > 0 {
err = syscall.Chroot(d.Chroot)
if err != nil {
d.pidFile.Remove()
return
}
}
Expand Down

0 comments on commit 1c1036e

Please sign in to comment.