]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/patches/squid/squid-asnbl-0.2.4_initialise_global_variables_to_make_compatible_with_python_3.patch
Tor: Update to 0.4.7.14
[people/pmueller/ipfire-2.x.git] / src / patches / squid / squid-asnbl-0.2.4_initialise_global_variables_to_make_compatible_with_python_3.patch
CommitLineData
df308429
AB
1--- squid-asnbl-0.2.4/asnbl-helper_orig.py
2+++ squid-asnbl-0.2.4/asnbl-helper.py
3@@ -172,17 +172,19 @@
4 return parsedasns
5
6
7-def resolve_asn(ipaddr: str, asndb):
8- """ Function call: resolve_asn(IP address to be resolved,
9- ASN database instance object)
10- This function looks up the Autonomous System for the given IP address. It expects
11- an IPFire location database object to be passed as a second parameter, hence relying
12- on another function to set that up. """
13+def resolve_asn(ipaddr: str):
14+ """ Function call: resolve_asn(IP address to be resolved)
15+ This function looks up the Autonomous System for the given IP address. """
16+
17+ # Fix for #13023
18+ # Initialize the result variable before it's first use, otherwise python3
19+ # will sometimes detect a 'mismatch' using global and local variables
20+ lookup_result = None
21
22 # libloc cannot handle ipaddress objects here, so casting into a string is necessary
23 # for good measure, to avoid exceptions here...
24 try:
25- result = asndb.lookup(str(ipaddr))
26+ lookup_result = ASNDB.lookup(str(ipaddr))
27 except BlockingIOError:
28 # XXX: Prevent likely libloc bug from causing this helper to crash
29 # (see upstream bug https://bugzilla.ipfire.org/show_bug.cgi?id=13023)
30@@ -190,21 +192,25 @@
31
32 # In case nothing was returned above, satisfy result expectation to this function...
33 try:
34- if not result.asn:
35+ if not lookup_result.asn:
36 return 0
37 except AttributeError:
38 return 0
39
40- return result.asn
41-
42-
43-def asndb_response_tests(testdata: str, asndb):
44- """ Function call: asndb_response_tests(response rest data,
45- ASN database instance object)
46+ return lookup_result.asn
47+
48+
49+def asndb_response_tests(testdata: str):
50+ """ Function call: asndb_response_tests(response rest data)
51
52 This function asserts the given ASN database to return expected ASNs for
53 given IP addresses in order to be considered operational. It returns
54 True if this test succeeds, and False otherwise. """
55+
56+ # Fix for #13023
57+ # Initialize the result variable before it's first use, otherwise python3
58+ # will sometimes detect a 'mismatch' using global and local variables
59+ lookup_result_test = None
60
61 tresult = True
62
63@@ -216,13 +222,13 @@
64
65 for stestdata in ptdata:
66 LOGIT.debug("Running response test for '%s' against ASNDB '%s' ...",
67- stestdata, asndb)
68-
69- returndata = resolve_asn(stestdata[0], asndb)
70-
71- if returndata != int(stestdata[1]):
72+ stestdata, ASNDB)
73+
74+ lookup_result_test = resolve_asn(stestdata[0])
75+
76+ if lookup_result_test != int(stestdata[1]):
77 LOGIT.error("Response test failed for ASNDB '%s' (tuple: %s), aborting",
78- asndb, stestdata)
79+ ASNDB, stestdata)
80 tresult = False
81 break
82
83@@ -428,7 +434,7 @@
84 ASNDB = set_up_location_database(config["GENERAL"]["ASNDB_PATH"])
85
86 LOGIT.debug("Running ASN database response tests...")
87-if asndb_response_tests(config["GENERAL"]["TESTDATA"], ASNDB):
88+if asndb_response_tests(config["GENERAL"]["TESTDATA"]):
89 LOGIT.debug("ASN database operational - excellent. Waiting for input...")
90 else:
91 LOGIT.error("ASN database response tests failed, aborting")
92@@ -490,7 +496,7 @@
93 ASNS = []
94 for singleip in IPS:
95 # Enumerate ASN for this IP address...
96- resolvedasn = resolve_asn(singleip, ASNDB)
97+ resolvedasn = resolve_asn(singleip)
98
99 # In case protection against destinations without public AS announcements for their
100 # IP addresses is desired, the query will be denied in case ASN = 0 appears in an