]> granicus.if.org Git - python/commitdiff
#6944: the argument to PyArg_ParseTuple should be a tuple, otherwise a SystemError...
authorGeorg Brandl <georg@python.org>
Sat, 19 Sep 2009 07:35:07 +0000 (07:35 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 19 Sep 2009 07:35:07 +0000 (07:35 +0000)
Lib/test/test_socket.py
Misc/NEWS
Modules/socketmodule.c

index 4b26824f7fca76d72862077accbc639019d7216b..66a402b4e38a2ac51288a80a0a9f2c1a4e00a403 100644 (file)
@@ -281,7 +281,7 @@ class GeneralModuleTests(unittest.TestCase):
                 # On some versions, this loses a reference
                 orig = sys.getrefcount(__name__)
                 socket.getnameinfo(__name__,0)
-            except SystemError:
+            except TypeError:
                 if sys.getrefcount(__name__) <> orig:
                     self.fail("socket.getnameinfo loses a reference")
 
index 8b0a67853a924578c4053f8d853059ddb7ddc60a..cac78e1c947746e7d86bc06fd578b3d7629894f5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1333,6 +1333,9 @@ C-API
 Extension Modules
 -----------------
 
+- Issue #6944: Fix a SystemError when socket.getnameinfo() was called
+  with something other than a tuple as first argument.
+
 - Issue #6865: Fix reference counting issue in the initialization of the pwd
   module.
 
index 5575855ef7d5d2f8aaccd528edac705fa10e85ea..18cce690a8b02b566904d2276ae1f0dc9cd3404d 100644 (file)
@@ -4100,8 +4100,13 @@ socket_getnameinfo(PyObject *self, PyObject *args)
        flags = flowinfo = scope_id = 0;
        if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags))
                return NULL;
-       if  (!PyArg_ParseTuple(sa, "si|ii",
-                              &hostp, &port, &flowinfo, &scope_id))
+       if (!PyTuple_Check(sa)) {
+               PyErr_SetString(PyExc_TypeError,
+                               "getnameinfo() argument 1 must be a tuple");
+               return NULL;
+       }
+       if (!PyArg_ParseTuple(sa, "si|ii",
+                             &hostp, &port, &flowinfo, &scope_id))
                return NULL;
        PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
        memset(&hints, 0, sizeof(hints));
@@ -4124,9 +4129,7 @@ socket_getnameinfo(PyObject *self, PyObject *args)
        switch (res->ai_family) {
        case AF_INET:
            {
-               char *t1;
-               int t2;
-               if (PyArg_ParseTuple(sa, "si", &t1, &t2) == 0) {
+               if (PyTuple_GET_SIZE(sa) != 2) {
                        PyErr_SetString(socket_error,
                                "IPv4 sockaddr must be 2 tuple");
                        goto fail;