[pypy-svn] r76770 - in pypy/trunk/pypy/module/_socket: . test

agaynor at codespeak.net agaynor at codespeak.net
Sat Aug 28 18:59:09 CEST 2010


Author: agaynor
Date: Sat Aug 28 18:59:08 2010
New Revision: 76770

Modified:
   pypy/trunk/pypy/module/_socket/interp_socket.py
   pypy/trunk/pypy/module/_socket/test/test_sock_app.py
Log:
Prevent a crash from an unhandled exception in _socket.socket.connect_ex when a bad address is provided.

Modified: pypy/trunk/pypy/module/_socket/interp_socket.py
==============================================================================
--- pypy/trunk/pypy/module/_socket/interp_socket.py	(original)
+++ pypy/trunk/pypy/module/_socket/interp_socket.py	Sat Aug 28 18:59:08 2010
@@ -74,7 +74,11 @@
         This is like connect(address), but returns an error code (the errno value)
         instead of raising an exception when an error occurs.
         """
-        error = self.connect_ex(self.addr_from_object(space, w_addr))
+        try:
+            addr = self.addr_from_object(space, w_addr)
+        except SocketError, e:
+            raise converted_error(space, e)
+        error = self.connect_ex(addr)
         return space.wrap(error)
     connect_ex_w.unwrap_spec = ['self', ObjSpace, W_Root]
 

Modified: pypy/trunk/pypy/module/_socket/test/test_sock_app.py
==============================================================================
--- pypy/trunk/pypy/module/_socket/test/test_sock_app.py	(original)
+++ pypy/trunk/pypy/module/_socket/test/test_sock_app.py	Sat Aug 28 18:59:08 2010
@@ -339,6 +339,13 @@
         name = s.getpeername() # Will raise socket.error if not connected
         assert name[1] == 80
         s.close()
+    
+    def test_socket_connect_ex(self):
+        import _socket
+        s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
+        # Make sure we get an app-level error, not an interp one.
+        raises(_socket.gaierror, s.connect_ex, ("wrong.invalid", 80))
+        s.close()
 
     def test_socket_connect_typeerrors(self):
         tests = [



More information about the Pypy-commit mailing list