[pypy-commit] pypy py3.5-ssl: fail on socket recv_into if length <= -1 or the length is bigger than the buffer can hold + test
plan_rich
pypy.commits at gmail.com
Thu Dec 1 06:46:24 EST 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5-ssl
Changeset: r88787:3259c787b38b
Date: 2016-12-01 12:45 +0100
http://bitbucket.org/pypy/pypy/changeset/3259c787b38b/
Log: fail on socket recv_into if length <= -1 or the length is bigger
than the buffer can hold + test
diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -517,8 +517,12 @@
"""
rwbuffer = space.getarg_w('w*', w_buffer)
lgt = rwbuffer.getlength()
- if nbytes == 0 or nbytes > lgt:
+ if nbytes < 0:
+ raise oefmt(space.w_ValueError, "negative buffersize in recv_into")
+ if nbytes == 0:
nbytes = lgt
+ if lgt < nbytes:
+ raise oefmt(space.w_ValueError, "buffer too small for requested bytes")
try:
return space.wrap(self.sock.recvinto(rwbuffer, nbytes, flags))
except SocketError as e:
diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -868,6 +868,22 @@
posix.close(fileno)
cli.close()
+ def test_recv_into_params(self):
+ import os
+ import _socket
+ cli = _socket.socket()
+ cli.connect(self.serv.getsockname())
+ fileno, addr = self.serv._accept()
+ os.write(fileno, b"abcdef")
+ #
+ m = memoryview(bytearray(5))
+ raises(ValueError, cli.recv_into, m, -1)
+ raises(ValueError, cli.recv_into, m, 6)
+ cli.recv_into(m,5)
+ assert m.tobytes() == b"abcde"
+ os.close(fileno)
+ cli.close()
+
class AppTestErrno:
spaceconfig = {'usemodules': ['_socket', 'select']}
More information about the pypy-commit
mailing list