Skip to content

Commit

Permalink
inspector, test: Fix test bug detected by Coverity
Browse files Browse the repository at this point in the history
Error value was not checked. Turns out, uv_ip6_addr was actually called
on malformed IP (square brackets should not have been included).

PR-URL: #13799
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Eugene Ostroukhov authored and rvagg committed Jun 29, 2017
1 parent 132a58e commit e4ce720
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/cctest/test_inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@ class SocketWrapper {
contents_.clear();
uv_tcp_init(loop_, &socket_);
union {sockaddr generic; sockaddr_in v4; sockaddr_in6 v6;} addr;
int err = 0;
if (v6) {
uv_ip6_addr(host.c_str(), port, &addr.v6);
err = uv_ip6_addr(host.c_str(), port, &addr.v6);
} else {
uv_ip4_addr(host.c_str(), port, &addr.v4);
err = uv_ip4_addr(host.c_str(), port, &addr.v4);
}
int err = uv_tcp_connect(&connect_, &socket_, &addr.generic, Connected_);
ASSERT_EQ(0, err);
err = uv_tcp_connect(&connect_, &socket_, &addr.generic, Connected_);
ASSERT_EQ(0, err);
SPIN_WHILE(!connected_)
uv_read_start(reinterpret_cast<uv_stream_t*>(&socket_), AllocCallback,
Expand Down Expand Up @@ -618,7 +620,7 @@ TEST_F(InspectorSocketServerTest, BindsToIpV6) {
ASSERT_TRUE(server->Start());

SocketWrapper socket1(&loop);
socket1.Connect("[::]", server.port(), true);
socket1.Connect("::", server.port(), true);
socket1.Write(WsHandshakeRequest(MAIN_TARGET_ID));
socket1.Expect(WS_HANDSHAKE_RESPONSE);
server->Stop(ServerHolder::CloseCallback);
Expand Down

0 comments on commit e4ce720

Please sign in to comment.