[Python-checkins] r54594 - in python/trunk: Lib/test/test_socket.py Modules/socketmodule.c

facundo.batista python-checkins at python.org
Wed Mar 28 05:45:28 CEST 2007


Author: facundo.batista
Date: Wed Mar 28 05:45:20 2007
New Revision: 54594

Modified:
   python/trunk/Lib/test/test_socket.py
   python/trunk/Modules/socketmodule.c
Log:

Bug 1688393. Adds a control of negative values in
socket.recvfrom, which caused an ugly crash.


Modified: python/trunk/Lib/test/test_socket.py
==============================================================================
--- python/trunk/Lib/test/test_socket.py	(original)
+++ python/trunk/Lib/test/test_socket.py	Wed Mar 28 05:45:20 2007
@@ -597,6 +597,13 @@
     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):

Modified: python/trunk/Modules/socketmodule.c
==============================================================================
--- python/trunk/Modules/socketmodule.c	(original)
+++ python/trunk/Modules/socketmodule.c	Wed Mar 28 05:45:20 2007
@@ -2391,7 +2391,7 @@
 
 	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 @@
 	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 @@
 
 	if (recvlen < 0) {
 		PyErr_SetString(PyExc_ValueError,
-				"negative buffersize in recv");
+				"negative buffersize in recvfrom_into");
 		return NULL;
 	}
 	if (recvlen == 0) {


More information about the Python-checkins mailing list