summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2007-03-28 03:45:20 +0000
committerFacundo Batista <facundobatista@gmail.com>2007-03-28 03:45:20 +0000
commit1fe9f968a21843175c3cbd6adf632aa95d2f2bef (patch)
tree85658d73283cf4945e086b3b43224265667908c9
parentb20c500251949028d38b32112e864da3cd074be0 (diff)
downloadcpython-git-1fe9f968a21843175c3cbd6adf632aa95d2f2bef.tar.gz
Bug 1688393. Adds a control of negative values in
socket.recvfrom, which caused an ugly crash.
-rw-r--r--Lib/test/test_socket.py7
-rw-r--r--Modules/socketmodule.c10
2 files changed, 15 insertions, 2 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 5be3dc3b5e..24d1a5dd3d 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -597,6 +597,13 @@ class BasicUDPTest(ThreadedUDPSocketTest):
def _testRecvFrom(self):
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):
def testClose(self):
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index cc54098f6a..96682ca86d 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2391,7 +2391,7 @@ sock_recv_into(PySocketSockObject *s, PyObject *args, PyObject *kwds)
if (recvlen < 0) {
PyErr_SetString(PyExc_ValueError,
- "negative buffersize in recv");
+ "negative buffersize in recv_into");
return NULL;
}
if (recvlen == 0) {
@@ -2507,6 +2507,12 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
if (!PyArg_ParseTuple(args, "i|i:recvfrom", &recvlen, &flags))
return NULL;
+ if (recvlen < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "negative buffersize in recvfrom");
+ return NULL;
+ }
+
buf = PyString_FromStringAndSize((char *) 0, recvlen);
if (buf == NULL)
return NULL;
@@ -2560,7 +2566,7 @@ sock_recvfrom_into(PySocketSockObject *s, PyObject *args, PyObject* kwds)
if (recvlen < 0) {
PyErr_SetString(PyExc_ValueError,
- "negative buffersize in recv");
+ "negative buffersize in recvfrom_into");
return NULL;
}
if (recvlen == 0) {