summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2019-01-23 17:07:38 -0800
committerShentubot <shentubot@google.com>2019-01-23 17:08:48 -0800
commitaf89fb49af1c9112753c718eb8538bcd9d2a6c6c (patch)
tree70fe41a484762d19b12133f194b800a9b811f947 /test/syscalls
parent5f08f8fd8162fa2fc2ca7b862263081d8d07b206 (diff)
socket_netlink_route: ignore negative port ID values
netlink_autobind() sets a port id to a process ID, if this address is available. Otherwise, it will set a port id to a random negative value. PiperOrigin-RevId: 230631956 Change-Id: I11692e4fe9421e77d9406627b4e7772e4d9b105a
Diffstat (limited to 'test/syscalls')
-rw-r--r--test/syscalls/linux/socket_netlink_route.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/test/syscalls/linux/socket_netlink_route.cc b/test/syscalls/linux/socket_netlink_route.cc
index 9fc695460..5f83836df 100644
--- a/test/syscalls/linux/socket_netlink_route.cc
+++ b/test/syscalls/linux/socket_netlink_route.cc
@@ -17,6 +17,7 @@
#include <linux/rtnetlink.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <unistd.h>
#include <vector>
#include "gtest/gtest.h"
@@ -100,12 +101,13 @@ TEST(NetlinkRouteTest, ConnectBinds) {
&addrlen),
SyscallSucceeds());
EXPECT_EQ(addrlen, sizeof(addr));
- // This is the only netlink socket in the process, so it should get the PID as
- // the port id.
- //
- // N.B. Another process could theoretically have explicitly reserved our pid
- // as a port ID, but that is very unlikely.
- EXPECT_EQ(addr.nl_pid, getpid());
+
+ // Each test is running in a pid namespace, so another process can explicitly
+ // reserve our pid as a port ID. In this case, a negative portid value will be
+ // set.
+ if (static_cast<pid_t>(addr.nl_pid) > 0) {
+ EXPECT_EQ(addr.nl_pid, getpid());
+ }
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;