[compiler-rt] r300250 - [msan] Fix msan_test.cc by checking bind results before assuming IPv6 supported.
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 13:25:24 PDT 2017
Author: vitalybuka
Date: Thu Apr 13 15:25:24 2017
New Revision: 300250
URL: http://llvm.org/viewvc/llvm-project?rev=300250&view=rev
Log:
[msan] Fix msan_test.cc by checking bind results before assuming IPv6 supported.
Modified:
compiler-rt/trunk/lib/msan/tests/msan_test.cc
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=300250&r1=300249&r2=300250&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu Apr 13 15:25:24 2017
@@ -890,6 +890,9 @@ class SocketAddr {
virtual ~SocketAddr() = default;
virtual struct sockaddr *ptr() = 0;
virtual size_t size() const = 0;
+
+ template <class... Args>
+ static std::unique_ptr<SocketAddr> Create(int family, Args... args);
};
class SocketAddr4 : public SocketAddr {
@@ -928,6 +931,13 @@ class SocketAddr6 : public SocketAddr {
sockaddr_in6 sai_;
};
+template <class... Args>
+std::unique_ptr<SocketAddr> SocketAddr::Create(int family, Args... args) {
+ if (family == AF_INET)
+ return std::unique_ptr<SocketAddr>(new SocketAddr4(args...));
+ return std::unique_ptr<SocketAddr>(new SocketAddr6(args...));
+}
+
class MemorySanitizerIpTest : public ::testing::TestWithParam<int> {
public:
void SetUp() override {
@@ -936,9 +946,7 @@ class MemorySanitizerIpTest : public ::t
template <class... Args>
std::unique_ptr<SocketAddr> CreateSockAddr(Args... args) const {
- if (GetParam() == AF_INET)
- return std::unique_ptr<SocketAddr>(new SocketAddr4(args...));
- return std::unique_ptr<SocketAddr>(new SocketAddr6(args...));
+ return SocketAddr::Create(GetParam(), args...);
}
int CreateSocket(int socket_type) const {
@@ -952,7 +960,8 @@ std::vector<int> GetAvailableIpSocketFam
for (int i : {AF_INET, AF_INET6}) {
int s = socket(i, SOCK_STREAM, 0);
if (s > 0) {
- result.push_back(i);
+ auto sai = SocketAddr::Create(i, 0);
+ if (bind(s, sai->ptr(), sai->size()) == 0) result.push_back(i);
close(s);
}
}
More information about the llvm-commits
mailing list