blob: 5e6009c745f67b6bc7a72ff225a0cd34fac96b2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
|