Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/test_subprocess_pipe_proto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import unittest

from uvloop.loop import ReadSubprocessPipeProto, WriteSubprocessPipeProto


class TestSubprocessPipeProto(unittest.TestCase):
def test_rejects_non_process_owner(self):
with self.assertRaises(TypeError):
ReadSubprocessPipeProto(1, 7)
with self.assertRaises(TypeError):
WriteSubprocessPipeProto(1, 7)

def test_rejects_non_int_fd(self):
# Owner is checked first. A non-process still must not segfault.
with self.assertRaises(TypeError):
WriteSubprocessPipeProto(object(), 'nope')
17 changes: 12 additions & 5 deletions uvloop/handles/process.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,18 @@ cdef class UVProcessTransport(UVProcess):
class WriteSubprocessPipeProto(aio_BaseProtocol):

def __init__(self, proc, fd):
if UVLOOP_DEBUG:
if type(proc) is not UVProcessTransport:
raise TypeError
if not isinstance(fd, int):
raise TypeError
# Release builds used to cast `proc` and segfault. Reject a bad owner
# here so a mistaken constructor argument is a TypeError.
if type(proc) is not UVProcessTransport:
raise TypeError(
'proc must be a UVProcessTransport, not {!r}'.format(
type(proc).__name__,
),
)
if not isinstance(fd, int):
raise TypeError(
'fd must be an int, not {!r}'.format(type(fd).__name__),
)
self.proc = proc
self.fd = fd
self.pipe = None
Expand Down
Loading