blob: fd77f4875083c6171421814a9651e7ecea8ed805 (
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
|
# Copyright 2010-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
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], str):
continue
except TypeError:
continue
valid_addrinfos.append(addrinfo)
return valid_addrinfos
|