aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_netinfo.c
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2018-12-18 11:58:40 +0200
committerrl1987 <rl1987@sdf.lonestar.org>2018-12-18 12:10:08 +0200
commitc92c0cbc9f7a1ad889cfdda6943ca484d110438e (patch)
treef939757e31abec3490371f5d37460b1defa4dd70 /src/test/test_netinfo.c
parent5b2acbec0e50a1858c43d0cafe9c4696152cde27 (diff)
downloadtor-c92c0cbc9f7a1ad889cfdda6943ca484d110438e.tar.gz
tor-c92c0cbc9f7a1ad889cfdda6943ca484d110438e.zip
Actually allow unrecognized address types in NETINFO cell
Ignore the address value instead of failing with error condition in case unrecognized address type is found.
Diffstat (limited to 'src/test/test_netinfo.c')
-rw-r--r--src/test/test_netinfo.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/test_netinfo.c b/src/test/test_netinfo.c
new file mode 100644
index 0000000000..1fee2a1eba
--- /dev/null
+++ b/src/test/test_netinfo.c
@@ -0,0 +1,48 @@
+/* Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+#include "core/or/or.h" // XXX: is this needed?
+#include "trunnel/netinfo.h"
+#include "test/test.h"
+
+static void
+test_netinfo_unsupported_addr(void *arg)
+{
+ const uint8_t wire_data[] =
+ { // TIME
+ 0x00, 0x00, 0x00, 0x01,
+ // OTHERADDR
+ 0x04, // ATYPE
+ 0x04, // ALEN
+ 0x08, 0x08, 0x08, 0x08, // AVAL
+ 0x01, // NMYADDR
+ 0x03, // ATYPE (unsupported)
+ 0x05, // ALEN
+ 'a', 'd', 'r', 'r', '!' // AVAL (unsupported)
+ };
+
+ (void)arg;
+
+ netinfo_cell_t *parsed_cell = NULL;
+
+ ssize_t parsed = netinfo_cell_parse(&parsed_cell, wire_data,
+ sizeof(wire_data));
+
+ tt_assert(parsed == sizeof(wire_data));
+
+ netinfo_addr_t *addr = netinfo_cell_get_my_addrs(parsed_cell, 0);
+ tt_assert(addr);
+
+ tt_int_op(3, OP_EQ, netinfo_addr_get_addr_type(addr));
+ tt_int_op(5, OP_EQ, netinfo_addr_get_len(addr));
+
+ done:
+ netinfo_cell_free(parsed_cell);
+}
+
+struct testcase_t netinfo_tests[] = {
+ { "unsupported_addr", test_netinfo_unsupported_addr, 0, NULL, NULL },
+ END_OF_TESTCASES
+};
+