aboutsummaryrefslogtreecommitdiffstats
path: root/tests/socket
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-08-31 18:56:10 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2020-08-31 18:59:04 +0200
commitd9e04177a263bb1ac1075c097fe4950f6c18f106 (patch)
tree999e67eec603f23e3df9ef8d2ede0309664f6deb /tests/socket
parent5cc4fe470645cff36cb2fed7aadd3ff2f224dd40 (diff)
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
Diffstat (limited to 'tests/socket')
-rw-r--r--tests/socket/socket_test.c6
-rw-r--r--tests/socket/socket_test.err1
-rw-r--r--tests/socket/socket_test.ok1
3 files changed, 8 insertions, 0 deletions
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 <string.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@@ -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