aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_helpers.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-01-03 10:11:23 -0500
committerNick Mathewson <nickm@torproject.org>2017-01-03 10:17:00 -0500
commitc4a6b56cc19878de4c76e83ce8e38ad709839d92 (patch)
tree8dcacd5e9b1bf64e412410fe22321ae0b2753756 /src/test/test_helpers.c
parentf23ec14d62f82ee424b7aef9ff1c2253c3dd2b10 (diff)
downloadtor-c4a6b56cc19878de4c76e83ce8e38ad709839d92.tar.gz
tor-c4a6b56cc19878de4c76e83ce8e38ad709839d92.zip
Fix unit test failures in response to DNS hijacking.
Some DNS NXDOMAIN hijackers hijack truly ridiculous domains, like "invalid-stuff!!" or "1.2.3.4.5". This would provoke unit test failures where we used addresses like that to force tor_addr_lookup() to fail. The fix, for testing, is to mock tor_addr_lookup() with a variant that always fails when it gets a name with a !. Fixes bugs 20862 and 20863.
Diffstat (limited to 'src/test/test_helpers.c')
-rw-r--r--src/test/test_helpers.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c
index 132af39776..5b84366e6d 100644
--- a/src/test/test_helpers.c
+++ b/src/test/test_helpers.c
@@ -128,3 +128,18 @@ dummy_origin_circuit_new(int n_cells)
return TO_CIRCUIT(circ);
}
+/** Mock-replacement. As tor_addr_lookup, but always fails on any
+ * address containing a !. This is necessary for running the unit tests
+ * on networks where DNS hijackers think it's helpful to give answers
+ * for things like 1.2.3.4.5 or "invalidstuff!!"
+ */
+int
+mock_tor_addr_lookup__fail_on_bad_addrs(const char *name,
+ uint16_t family, tor_addr_t *out)
+{
+ if (name && strchr(name, '!')) {
+ return -1;
+ }
+ return tor_addr_lookup__real(name, family, out);
+}
+