GUACAMOLE-513: Handle cases where socket open fails.

This commit is contained in:
Nick Couchman 2020-06-09 19:27:07 -04:00
parent 9ca382e2aa
commit 30bbb892db

View File

@ -94,6 +94,12 @@ static ssize_t __guac_wol_send_packet(const char* broadcast_addr,
int wol_bcast = 1; int wol_bcast = 1;
wol_socket = socket(AF_INET, SOCK_DGRAM, 0); wol_socket = socket(AF_INET, SOCK_DGRAM, 0);
/* If opening a socket fails, bail out. */
if (wol_socket < 0) {
close(wol_socket);
return 0;
}
/* Attempt to set broadcast; exit with error if this fails. */ /* Attempt to set broadcast; exit with error if this fails. */
if (setsockopt(wol_socket, SOL_SOCKET, SO_BROADCAST, &wol_bcast, if (setsockopt(wol_socket, SOL_SOCKET, SO_BROADCAST, &wol_bcast,
sizeof(wol_bcast)) < 0) { sizeof(wol_bcast)) < 0) {
@ -106,6 +112,12 @@ static ssize_t __guac_wol_send_packet(const char* broadcast_addr,
else { else {
wol_socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); wol_socket = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
/* If opening the socket fails, bail out. */
if (wol_socket < 0) {
close(wol_socket);
return 0;
}
/* Stick to a single hop for now. */ /* Stick to a single hop for now. */
int hops = 1; int hops = 1;