summaryrefslogtreecommitdiffstats
path: root/pym/_emerge/sync
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-10-13 19:30:40 -0700
committerZac Medico <zmedico@gentoo.org>2010-10-13 19:30:40 -0700
commitc54c1af789b306a85e9d7e79fb54f02a05346616 (patch)
tree54f164ccc84d71b94797310c96179923a1795eff /pym/_emerge/sync
parentf2fce065ab4d248268e60ca549480e6967cfbe1a (diff)
downloadportage-c54c1af789b306a85e9d7e79fb54f02a05346616.tar.gz
portage-c54c1af789b306a85e9d7e79fb54f02a05346616.tar.bz2
portage-c54c1af789b306a85e9d7e79fb54f02a05346616.zip
Bug #340899 - Validate getaddrinfo() results.
Diffstat (limited to 'pym/_emerge/sync')
-rw-r--r--pym/_emerge/sync/getaddrinfo_validate.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/pym/_emerge/sync/getaddrinfo_validate.py b/pym/_emerge/sync/getaddrinfo_validate.py
new file mode 100644
index 000000000..5e6009c74
--- /dev/null
+++ b/pym/_emerge/sync/getaddrinfo_validate.py
@@ -0,0 +1,29 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import sys
+
+if sys.hexversion >= 0x3000000:
+ basestring = str
+
+def getaddrinfo_validate(addrinfos):
+ """
+ Validate structures returned from getaddrinfo(),
+ since they may be corrupt, especially when python
+ has IPv6 support disabled (bug #340899).
+ """
+ valid_addrinfos = []
+ for addrinfo in addrinfos:
+ try:
+ if len(addrinfo) != 5:
+ continue
+ if len(addrinfo[4]) < 2:
+ continue
+ if not isinstance(addrinfo[4][0], basestring):
+ continue
+ except TypeError:
+ continue
+
+ valid_addrinfos.append(addrinfo)
+
+ return valid_addrinfos