diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-10-13 19:30:40 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-10-13 20:39:29 -0700 |
commit | 5840dd352c4bd4af8a8432c0dad1a4a2fc230b90 (patch) | |
tree | f5b50449b98d6644b505df2afb63acfedd4db5f8 /pym/_emerge/sync/getaddrinfo_validate.py | |
parent | ac630d170f7f5c685f1b019ea2cc2c53157ac087 (diff) | |
download | portage-5840dd352c4bd4af8a8432c0dad1a4a2fc230b90.tar.gz portage-5840dd352c4bd4af8a8432c0dad1a4a2fc230b90.tar.bz2 portage-5840dd352c4bd4af8a8432c0dad1a4a2fc230b90.zip |
Bug #340899 - Validate getaddrinfo() results.
Diffstat (limited to 'pym/_emerge/sync/getaddrinfo_validate.py')
-rw-r--r-- | pym/_emerge/sync/getaddrinfo_validate.py | 29 |
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 |