Skip to content

Commit

Permalink
Fix segmentation fault when closing secure tunnel with null websocket (
Browse files Browse the repository at this point in the history
…#71)

* Fix segmentation fault when closing secure tunnel with null websocket
* This commit adds a NULL check on the websocket member inside of the aws_secure_tunnel_close function.
  • Loading branch information
marcoemorais-aws authored May 26, 2022
1 parent 9a5d6a8 commit b50828c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/secure_tunneling.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,11 @@ static int s_secure_tunneling_close(struct aws_secure_tunnel *secure_tunnel) {
}

s_reset_secure_tunnel(secure_tunnel);
secure_tunnel->websocket_vtable.close(secure_tunnel->websocket, false);
secure_tunnel->websocket_vtable.release(secure_tunnel->websocket);
secure_tunnel->websocket = NULL;
if (secure_tunnel->websocket != NULL) {
secure_tunnel->websocket_vtable.close(secure_tunnel->websocket, false);
secure_tunnel->websocket_vtable.release(secure_tunnel->websocket);
secure_tunnel->websocket = NULL;
}
return AWS_OP_SUCCESS;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/secure_tunneling_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ static struct aws_secure_tunnel *s_secure_tunnel_new_mock(const struct aws_secur
secure_tunnel->websocket_vtable.send_frame = s_mock_aws_websocket_send_frame;
secure_tunnel->websocket_vtable.close = s_mock_aws_websocket_close;
secure_tunnel->websocket_vtable.release = s_mock_aws_websocket_release;

/*
* Initialize a dummy websocket when the tunnel is created.
*
* In the non-mock implementation this websocket would be initialized when
* an http upgrade request is received sometime after the tunnel is created.
*
* Since no http request is exercised by these tests we initialize a websocket
* as soon as the tunnel is created. Since the aws_websocket struct is opaque
* to this module, we use the placeholder value 1 to set the member non-null.
*/
secure_tunnel->websocket = (void *)1;

return secure_tunnel;
}

Expand Down

0 comments on commit b50828c

Please sign in to comment.