Author: Richard Plangger <planri...@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']}
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to