vstinner / rpms / python3

Forked from rpms/python3 5 years ago
Clone
c8f16f3
c8f16f3
# HG changeset patch
c8f16f3
# User Benjamin Peterson <benjamin@python.org>
c8f16f3
# Date 1389672775 18000
c8f16f3
# Node ID 7f176a45211ff3cb85a2fbdc75f7979d642bb563
c8f16f3
# Parent  ed1c27b68068c942c6e845bdf8e987e963d50920# Parent  9c56217e5c793685eeaf0ee224848c402bdf1e4c
c8f16f3
merge 3.2 (#20246)
c8f16f3
c8f16f3
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
c8f16f3
--- a/Lib/test/test_socket.py
c8f16f3
+++ b/Lib/test/test_socket.py
c8f16f3
@@ -4538,6 +4538,14 @@ class BufferIOTest(SocketConnectedTest):
c8f16f3
 
c8f16f3
     _testRecvFromIntoMemoryview = _testRecvFromIntoArray
c8f16f3
 
c8f16f3
+    def testRecvFromIntoSmallBuffer(self):
c8f16f3
+        # See issue #20246.
c8f16f3
+        buf = bytearray(8)
c8f16f3
+        self.assertRaises(ValueError, self.cli_conn.recvfrom_into, buf, 1024)
c8f16f3
+
c8f16f3
+    def _testRecvFromIntoSmallBuffer(self):
c8f16f3
+        self.serv_conn.send(MSG*2048)
c8f16f3
+
c8f16f3
 
c8f16f3
 TIPC_STYPE = 2000
c8f16f3
 TIPC_LOWER = 200
c8f16f3
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
c8f16f3
--- a/Modules/socketmodule.c
c8f16f3
+++ b/Modules/socketmodule.c
c8f16f3
@@ -2935,6 +2935,11 @@ sock_recvfrom_into(PySocketSockObject *s
c8f16f3
     if (recvlen == 0) {
c8f16f3
         /* If nbytes was not specified, use the buffer's length */
c8f16f3
         recvlen = buflen;
c8f16f3
+    } else if (recvlen > buflen) {
c8f16f3
+        PyBuffer_Release(&pbuf);
c8f16f3
+        PyErr_SetString(PyExc_ValueError,
c8f16f3
+                        "nbytes is greater than the length of the buffer");
c8f16f3
+        return NULL;
c8f16f3
     }
c8f16f3
 
c8f16f3
     readlen = sock_recvfrom_guts(s, buf, recvlen, flags, &addr);
c8f16f3