]> git.pld-linux.org Git - packages/python.git/blob - python-buffer-overflow.patch
fix buffer overflow in socket.recvfrom_into
[packages/python.git] / python-buffer-overflow.patch
1
2 # HG changeset patch
3 # User Benjamin Peterson <benjamin@python.org>
4 # Date 1389671978 18000
5 # Node ID 87673659d8f7ba1623cd4914f09ad3d2ade034e9
6 # Parent  2631d33ee7fbd5f0288931ef37872218d511d2e8
7 complain when nbytes > buflen to fix possible buffer overflow (closes #20246)
8
9 diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
10 --- a/Lib/test/test_socket.py
11 +++ b/Lib/test/test_socket.py
12 @@ -1620,6 +1620,16 @@ class BufferIOTest(SocketConnectedTest):
13  
14      _testRecvFromIntoMemoryview = _testRecvFromIntoArray
15  
16 +    def testRecvFromIntoSmallBuffer(self):
17 +        # See issue #20246.
18 +        buf = bytearray(8)
19 +        self.assertRaises(ValueError, self.cli_conn.recvfrom_into, buf, 1024)
20 +
21 +    def _testRecvFromIntoSmallBuffer(self):
22 +        with test_support.check_py3k_warnings():
23 +            buf = buffer(MSG*2048)
24 +        self.serv_conn.send(buf)
25 +
26  
27  TIPC_STYPE = 2000
28  TIPC_LOWER = 200
29 diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
30 --- a/Modules/socketmodule.c
31 +++ b/Modules/socketmodule.c
32 @@ -2742,6 +2742,10 @@ sock_recvfrom_into(PySocketSockObject *s
33      if (recvlen == 0) {
34          /* If nbytes was not specified, use the buffer's length */
35          recvlen = buflen;
36 +    } else if (recvlen > buflen) {
37 +        PyErr_SetString(PyExc_ValueError,
38 +                        "nbytes is greater than the length of the buffer");
39 +        goto error;
40      }
41  
42      readlen = sock_recvfrom_guts(s, buf.buf, recvlen, flags, &addr);
43
This page took 0.071301 seconds and 3 git commands to generate.