Skip to content

Commit c6a3229

Browse files
committed
Protect pty.Resize on windows from races
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent 439107d commit c6a3229

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pty/pty_windows.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ func (p *ptyWindows) InputWriter() io.Writer {
122122
}
123123

124124
func (p *ptyWindows) Resize(height uint16, width uint16) error {
125+
// hold the lock, so we don't race with anyone trying to close the console
126+
p.closeMutex.Lock()
127+
defer p.closeMutex.Unlock()
128+
if p.closed || p.console == windows.InvalidHandle {
129+
return pty.ErrClosed
130+
}
125131
// Taken from: https://github.com/microsoft/hcsshim/blob/54a5ad86808d761e3e396aff3e2022840f39f9a8/internal/winapi/zsyscall_windows.go#L144
126132
ret, _, err := procResizePseudoConsole.Call(uintptr(p.console), uintptr(*((*uint32)(unsafe.Pointer(&windows.Coord{
127133
Y: int16(height),

0 commit comments

Comments
 (0)