[VM/Tests] - Fix new abstract_socket_test.
- Skip in configurations that do not build the abstract_socket_test
executable
- Fix MemorySanitizer: use-of-uninitialized-value error
TEST=existing test - unix-socket-test
Change-Id: Ie9bf6dc1cd6bea98cd7859584473154f6ac49eee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201722
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
diff --git a/runtime/bin/socket_base.cc b/runtime/bin/socket_base.cc
index 7a62ab8..d97ced4 100644
--- a/runtime/bin/socket_base.cc
+++ b/runtime/bin/socket_base.cc
@@ -34,7 +34,8 @@
}
}
-intptr_t SocketAddress::GetAddrLength(const RawAddr& addr) {
+intptr_t SocketAddress::GetAddrLength(const RawAddr& addr,
+ bool unnamed_unix_socket) {
ASSERT((addr.ss.ss_family == AF_INET) || (addr.ss.ss_family == AF_INET6) ||
(addr.ss.ss_family == AF_UNIX));
switch (addr.ss.ss_family) {
@@ -53,7 +54,7 @@
// trailing null bytes on purpose.
// https://github.com/dart-lang/sdk/issues/46158
intptr_t nulls = 0;
- if (addr.un.sun_path[0] == '\0') {
+ if (!unnamed_unix_socket && addr.un.sun_path[0] == '\0') {
intptr_t i = sizeof(addr.un.sun_path) - 1;
while (addr.un.sun_path[i] == '\0') {
nulls++;
diff --git a/runtime/bin/socket_base.h b/runtime/bin/socket_base.h
index bf9405e..07ee42e 100644
--- a/runtime/bin/socket_base.h
+++ b/runtime/bin/socket_base.h
@@ -69,7 +69,8 @@
const char* as_string() const { return as_string_; }
const RawAddr& addr() const { return addr_; }
- static intptr_t GetAddrLength(const RawAddr& addr);
+ static intptr_t GetAddrLength(const RawAddr& addr,
+ bool unnamed_unix_socket = false);
static intptr_t GetInAddrLength(const RawAddr& addr);
static bool AreAddressesEqual(const RawAddr& a, const RawAddr& b);
static void GetSockAddr(Dart_Handle obj, RawAddr* addr);
diff --git a/runtime/bin/socket_base_android.cc b/runtime/bin/socket_base_android.cc
index 9085f14..68163c6 100644
--- a/runtime/bin/socket_base_android.cc
+++ b/runtime/bin/socket_base_android.cc
@@ -40,7 +40,8 @@
as_string_[0] = 0;
}
}
- socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa));
+ socklen_t salen =
+ GetAddrLength(*reinterpret_cast<RawAddr*>(sa), unnamed_unix_socket);
memmove(reinterpret_cast<void*>(&addr_), sa, salen);
}
diff --git a/runtime/bin/socket_base_linux.cc b/runtime/bin/socket_base_linux.cc
index 8734aa6..89e579f 100644
--- a/runtime/bin/socket_base_linux.cc
+++ b/runtime/bin/socket_base_linux.cc
@@ -40,7 +40,8 @@
as_string_[0] = 0;
}
}
- socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa));
+ socklen_t salen =
+ GetAddrLength(*reinterpret_cast<RawAddr*>(sa), unnamed_unix_socket);
memmove(reinterpret_cast<void*>(&addr_), sa, salen);
}
diff --git a/runtime/bin/socket_base_macos.cc b/runtime/bin/socket_base_macos.cc
index 74bf924..0b259ee 100644
--- a/runtime/bin/socket_base_macos.cc
+++ b/runtime/bin/socket_base_macos.cc
@@ -39,7 +39,8 @@
as_string_[0] = 0;
}
}
- socklen_t salen = GetAddrLength(*reinterpret_cast<RawAddr*>(sa));
+ socklen_t salen =
+ GetAddrLength(*reinterpret_cast<RawAddr*>(sa), unnamed_unix_socket);
memmove(reinterpret_cast<void*>(&addr_), sa, salen);
}
diff --git a/tests/standalone/io/unix_socket_test.dart b/tests/standalone/io/unix_socket_test.dart
index d5ee7cb..7c84792 100644
--- a/tests/standalone/io/unix_socket_test.dart
+++ b/tests/standalone/io/unix_socket_test.dart
@@ -179,6 +179,11 @@
try {
var socketAddress = '@hidden';
var abstractSocketServer = getAbstractSocketTestFileName();
+ // check if the executable exists, some build configurations do not
+ // build it (e.g: precompiled simarm/simarm64)
+ if (!File(abstractSocketServer).existsSync()) {
+ return;
+ }
process = await Process.start(abstractSocketServer, [socketAddress]);
var serverAddress =
InternetAddress(socketAddress, type: InternetAddressType.unix);
diff --git a/tests/standalone_2/io/unix_socket_test.dart b/tests/standalone_2/io/unix_socket_test.dart
index aa86ae8..0549fea 100644
--- a/tests/standalone_2/io/unix_socket_test.dart
+++ b/tests/standalone_2/io/unix_socket_test.dart
@@ -181,6 +181,11 @@
try {
var socketAddress = '@hidden';
var abstractSocketServer = getAbstractSocketTestFileName();
+ // check if the executable exists, some build configurations do not
+ // build it (e.g: precompiled simarm/simarm64)
+ if (!File(abstractSocketServer).existsSync()) {
+ return;
+ }
process = await Process.start(abstractSocketServer, [socketAddress]);
var serverAddress =
InternetAddress(socketAddress, type: InternetAddressType.unix);