Skip to content

Commit

Permalink
[VM/Tests] - Fix new abstract_socket_test.
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
a-siva authored and commit-bot@chromium.org committed May 29, 2021
1 parent d05093e commit 0742ed6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
5 changes: 3 additions & 2 deletions runtime/bin/socket_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ int SocketAddress::GetType() {
}
}

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) {
Expand All @@ -53,7 +54,7 @@ intptr_t SocketAddress::GetAddrLength(const RawAddr& addr) {
// 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++;
Expand Down
3 changes: 2 additions & 1 deletion runtime/bin/socket_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class SocketAddress {
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);
Expand Down
3 changes: 2 additions & 1 deletion runtime/bin/socket_base_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ SocketAddress::SocketAddress(struct sockaddr* sa, bool unnamed_unix_socket) {
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);
}

Expand Down
3 changes: 2 additions & 1 deletion runtime/bin/socket_base_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ SocketAddress::SocketAddress(struct sockaddr* sa, bool unnamed_unix_socket) {
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);
}

Expand Down
3 changes: 2 additions & 1 deletion runtime/bin/socket_base_macos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ SocketAddress::SocketAddress(struct sockaddr* sa, bool unnamed_unix_socket) {
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);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/standalone/io/unix_socket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ Future testShortAbstractAddress() async {
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);
Expand Down
5 changes: 5 additions & 0 deletions tests/standalone_2/io/unix_socket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ Future testShortAbstractAddress() async {
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);
Expand Down

0 comments on commit 0742ed6

Please sign in to comment.