]> granicus.if.org Git - python/commitdiff
Patch #1511317: don't crash on invalid hostname info
authorGeorg Brandl <georg@python.org>
Mon, 14 Aug 2006 22:10:24 +0000 (22:10 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 14 Aug 2006 22:10:24 +0000 (22:10 +0000)
Modules/socketmodule.c

index bb99bdeb9de247f3ac8a27eb206f02bb80ed7e0d..f03b34c057f8689683bba791bc53d9b06dbe704d 100644 (file)
@@ -3041,17 +3041,20 @@ gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af)
        if ((addr_list = PyList_New(0)) == NULL)
                goto err;
 
-       for (pch = h->h_aliases; *pch != NULL; pch++) {
-               int status;
-               tmp = PyString_FromString(*pch);
-               if (tmp == NULL)
-                       goto err;
-
-               status = PyList_Append(name_list, tmp);
-               Py_DECREF(tmp);
-
-               if (status)
-                       goto err;
+       /* SF #1511317: h_aliases can be NULL */
+       if (h->h_aliases) {
+               for (pch = h->h_aliases; *pch != NULL; pch++) {
+                       int status;
+                       tmp = PyString_FromString(*pch);
+                       if (tmp == NULL)
+                               goto err;
+
+                       status = PyList_Append(name_list, tmp);
+                       Py_DECREF(tmp);
+
+                       if (status)
+                               goto err;
+               }
        }
 
        for (pch = h->h_addr_list; *pch != NULL; pch++) {