mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
Bug 1688393. Adds a control of negative values in
socket.recvfrom, which caused an ugly crash.
This commit is contained in:
parent
b20c500251
commit
1fe9f968a2
2 changed files with 15 additions and 2 deletions
|
@ -597,6 +597,13 @@ class BasicUDPTest(ThreadedUDPSocketTest):
|
||||||
def _testRecvFrom(self):
|
def _testRecvFrom(self):
|
||||||
self.cli.sendto(MSG, 0, (HOST, PORT))
|
self.cli.sendto(MSG, 0, (HOST, PORT))
|
||||||
|
|
||||||
|
def testRecvFromNegative(self):
|
||||||
|
# Negative lengths passed to recvfrom should give ValueError.
|
||||||
|
self.assertRaises(ValueError, self.serv.recvfrom, -1)
|
||||||
|
|
||||||
|
def _testRecvFromNegative(self):
|
||||||
|
self.cli.sendto(MSG, 0, (HOST, PORT))
|
||||||
|
|
||||||
class TCPCloserTest(ThreadedTCPSocketTest):
|
class TCPCloserTest(ThreadedTCPSocketTest):
|
||||||
|
|
||||||
def testClose(self):
|
def testClose(self):
|
||||||
|
|
|
@ -2391,7 +2391,7 @@ sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds)
|
||||||
|
|
||||||
if (recvlen < 0) {
|
if (recvlen < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"negative buffersize in recv");
|
"negative buffersize in recv_into");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (recvlen == 0) {
|
if (recvlen == 0) {
|
||||||
|
@ -2507,6 +2507,12 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags))
|
if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (recvlen < 0) {
|
||||||
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
"negative buffersize in recvfrom");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
buf = PyString_FromStringAndSize((char *) 0, recvlen);
|
buf = PyString_FromStringAndSize((char *) 0, recvlen);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2560,7 +2566,7 @@ sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds)
|
||||||
|
|
||||||
if (recvlen < 0) {
|
if (recvlen < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"negative buffersize in recv");
|
"negative buffersize in recvfrom_into");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (recvlen == 0) {
|
if (recvlen == 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue