From d9e04177a263bb1ac1075c097fe4950f6c18f106 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 31 Aug 2020 18:56:10 +0200 Subject: tests: Add test to showcase osmo_sock_init2 bug with AF_UNSPEC The function is checking for IP version matching between local and remote addresses even if only one is needed based on flags. For example, if user only desired to bind, the remote address should not be used nor checked. Bug was introduced here: 2c962f5de1eeea119cfac7d9d92db31c570353b9 Change-Id: I87afd1db9bd017426abcc959fa515d15784cdf1c --- tests/socket/socket_test.c | 6 ++++++ tests/socket/socket_test.err | 1 + tests/socket/socket_test.ok | 1 + 3 files changed, 8 insertions(+) (limited to 'tests/socket') diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c index a2e103c9..5cf20b7e 100644 --- a/tests/socket/socket_test.c +++ b/tests/socket/socket_test.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -143,6 +144,11 @@ static int test_sockinit2(void) OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT); OSMO_ASSERT(fd >= 0); + printf("Checking osmo_sock_init2(AF_UNSPEC) BIND on IPv4\n"); + fd = osmo_sock_init2(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "127.0.0.1", 0, NULL, 0, + OSMO_SOCK_F_BIND); + OSMO_ASSERT(fd == -ENODEV); /* BUG! */ + talloc_free(name); return 0; diff --git a/tests/socket/socket_test.err b/tests/socket/socket_test.err index 0f0f8da8..37504e77 100644 --- a/tests/socket/socket_test.err +++ b/tests/socket/socket_test.err @@ -2,3 +2,4 @@ invalid: both bind and connect flags set: 0.0.0.0:0 invalid: you have to specify either BIND or CONNECT flags Unable to find a common protocol (IPv4 or IPv6) for local host: 127.0.0.1 and remote host: ::1. Unable to find a common protocol (IPv4 or IPv6) for local host: ::1 and remote host: 127.0.0.1. +Unable to find a common protocol (IPv4 or IPv6) for local host: 127.0.0.1 and remote host: (null). diff --git a/tests/socket/socket_test.ok b/tests/socket/socket_test.ok index 4265be8d..696e356b 100644 --- a/tests/socket/socket_test.ok +++ b/tests/socket/socket_test.ok @@ -9,3 +9,4 @@ Checking osmo_sock_init2(AF_UNSPEC) must fail on mixed IPv4 & IPv6 Checking osmo_sock_init2(AF_UNSPEC) must fail on mixed IPv6 & IPv4 Checking osmo_sock_init2(AF_UNSPEC) BIND + CONNECT on IPv4 Checking osmo_sock_init2(AF_UNSPEC) BIND + CONNECT on IPv6 +Checking osmo_sock_init2(AF_UNSPEC) BIND on IPv4 -- cgit v1.2.3