<p>pespin has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/19918">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">tests: Add test to showcase osmo_sock_init2 bug with AF_UNSPEC<br><br>The function is checking for IP version matching between local and<br>remote addresses even if only one is needed based on flags. For example,<br>if user only desired to bind, the remote address should not be<br>used nor checked.<br><br>Bug was introduced here: 2c962f5de1eeea119cfac7d9d92db31c570353b9<br><br>Change-Id: I87afd1db9bd017426abcc959fa515d15784cdf1c<br>---<br>M tests/socket/socket_test.c<br>M tests/socket/socket_test.err<br>M tests/socket/socket_test.ok<br>3 files changed, 8 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/18/19918/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/tests/socket/socket_test.c b/tests/socket/socket_test.c</span><br><span>index a2e103c..5cf20b7 100644</span><br><span>--- a/tests/socket/socket_test.c</span><br><span>+++ b/tests/socket/socket_test.c</span><br><span>@@ -24,6 +24,7 @@</span><br><span> #include <string.h></span><br><span> #include <fcntl.h></span><br><span> #include <inttypes.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <errno.h></span><br><span> </span><br><span> #include <sys/socket.h></span><br><span> #include <arpa/inet.h></span><br><span>@@ -143,6 +144,11 @@</span><br><span>                         OSMO_SOCK_F_BIND|OSMO_SOCK_F_CONNECT);</span><br><span>  OSMO_ASSERT(fd >= 0);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+  printf("Checking osmo_sock_init2(AF_UNSPEC) BIND on IPv4\n");</span><br><span style="color: hsl(120, 100%, 40%);">+       fd = osmo_sock_init2(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "127.0.0.1", 0, NULL, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+                        OSMO_SOCK_F_BIND);</span><br><span style="color: hsl(120, 100%, 40%);">+       OSMO_ASSERT(fd == -ENODEV); /* BUG! */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     talloc_free(name);</span><br><span> </span><br><span>       return 0;</span><br><span>diff --git a/tests/socket/socket_test.err b/tests/socket/socket_test.err</span><br><span>index 0f0f8da..37504e7 100644</span><br><span>--- a/tests/socket/socket_test.err</span><br><span>+++ b/tests/socket/socket_test.err</span><br><span>@@ -2,3 +2,4 @@</span><br><span> invalid: you have to specify either BIND or CONNECT flags</span><br><span> Unable to find a common protocol (IPv4 or IPv6) for local host: 127.0.0.1 and remote host: ::1.</span><br><span> Unable to find a common protocol (IPv4 or IPv6) for local host: ::1 and remote host: 127.0.0.1.</span><br><span style="color: hsl(120, 100%, 40%);">+Unable to find a common protocol (IPv4 or IPv6) for local host: 127.0.0.1 and remote host: (null).</span><br><span>diff --git a/tests/socket/socket_test.ok b/tests/socket/socket_test.ok</span><br><span>index 4265be8..696e356 100644</span><br><span>--- a/tests/socket/socket_test.ok</span><br><span>+++ b/tests/socket/socket_test.ok</span><br><span>@@ -9,3 +9,4 @@</span><br><span> Checking osmo_sock_init2(AF_UNSPEC) must fail on mixed IPv6 & IPv4</span><br><span> Checking osmo_sock_init2(AF_UNSPEC) BIND + CONNECT on IPv4</span><br><span> Checking osmo_sock_init2(AF_UNSPEC) BIND + CONNECT on IPv6</span><br><span style="color: hsl(120, 100%, 40%);">+Checking osmo_sock_init2(AF_UNSPEC) BIND on IPv4</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/19918">change 19918</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/19918"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I87afd1db9bd017426abcc959fa515d15784cdf1c </div>
<div style="display:none"> Gerrit-Change-Number: 19918 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>