diff --git a/libguac/src/client.c b/libguac/src/client.c index 3de42f73..276c7f83 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -190,9 +190,14 @@ guac_client* guac_get_client(int client_fd) { return NULL; } - /* Send args */ - guac_send_args(io, client_args); - guac_flush(io); + if ( /* Send args */ + guac_send_args(io, client_args) + || guac_flush(io) + ) { + guac_close(io); + guac_free_instruction_data(&instruction); + return NULL; + } guac_free_instruction_data(&instruction); break; @@ -292,8 +297,13 @@ void* __guac_client_output_thread(void* data) { long timestamp = guac_current_timestamp(); if (timestamp - client->last_sent_timestamp > GUAC_SYNC_FREQUENCY) { client->last_sent_timestamp = timestamp; - guac_send_sync(io, timestamp); - guac_flush(io); + if ( + guac_send_sync(io, timestamp) + || guac_flush(io) + ) { + guac_client_stop(client); + return NULL; + } } /* Handle server messages */ @@ -320,11 +330,18 @@ void* __guac_client_output_thread(void* data) { /* Send sync instruction */ client->last_sent_timestamp = guac_current_timestamp(); - guac_send_sync(io, client->last_sent_timestamp); + if (guac_send_sync(io, client->last_sent_timestamp)) { + guac_client_stop(client); + return NULL; + } } - guac_flush(io); + if (guac_flush(io)) { + guac_client_stop(client); + return NULL; + } + } /* If sync threshold exceeded, don't spin waiting for resync */ diff --git a/libguac/src/protocol.c b/libguac/src/protocol.c index 2591edd3..db003763 100644 --- a/libguac/src/protocol.c +++ b/libguac/src/protocol.c @@ -214,7 +214,7 @@ int guac_send_name(GUACIO* io, const char* name) { int guac_send_size(GUACIO* io, int w, int h) { return - guac_write_string(io, "size:") + guac_write_string(io, "size:") || guac_write_int(io, w) || guac_write_string(io, ",") || guac_write_int(io, h) @@ -227,7 +227,7 @@ int guac_send_clipboard(GUACIO* io, const char* data) { char* escaped = guac_escape_string(data); if ( - guac_write_string(io, "clipboard:") + guac_write_string(io, "clipboard:") || guac_write_string(io, escaped) || guac_write_string(io, ";") ) { @@ -245,7 +245,7 @@ int guac_send_error(GUACIO* io, const char* error) { char* escaped = guac_escape_string(error); if ( - guac_write_string(io, "error:") + guac_write_string(io, "error:") || guac_write_string(io, escaped) || guac_write_string(io, ";") ) { @@ -261,7 +261,7 @@ int guac_send_error(GUACIO* io, const char* error) { int guac_send_sync(GUACIO* io, long timestamp) { return - guac_write_string(io, "sync:") + guac_write_string(io, "sync:") || guac_write_int(io, timestamp) || guac_write_string(io, ";"); @@ -270,7 +270,7 @@ int guac_send_sync(GUACIO* io, long timestamp) { int guac_send_copy(GUACIO* io, int srcl, int srcx, int srcy, int w, int h, int dstl, int dstx, int dsty) { return - guac_write_string(io, "copy:") + guac_write_string(io, "copy:") || guac_write_int(io, srcl) || guac_write_string(io, ",") || guac_write_int(io, srcx) @@ -419,7 +419,7 @@ int guac_send_cursor(GUACIO* io, int x, int y, png_byte** png_rows, int w, int h ); if ( - guac_write_string(io, "cursor:") + guac_write_string(io, "cursor:") || guac_write_int(io, x) || guac_write_string(io, ",") || guac_write_int(io, y)