GUACAMOLE-1059: Add missing checks and fix up warning messages.

This commit is contained in:
Nick Couchman 2020-05-05 16:33:59 -04:00
parent 71769b9715
commit e761e47cd0
9 changed files with 135 additions and 80 deletions

View File

@ -137,9 +137,10 @@ void guac_rdpdr_fs_process_set_rename_info(guac_rdp_common_svc* svc,
/* Check stream size prior to reading. */ /* Check stream size prior to reading. */
if (Stream_GetRemainingLength(input_stream) < 6) { if (Stream_GetRemainingLength(input_stream) < 6) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Set "
"contain the required number of bytes. File sharing may not " "Information Request (FileRenameInformation) PDU does not "
"work as expected."); "contain the expected number of bytes. File redirection "
"may not work as expected.");
return; return;
} }
@ -148,6 +149,14 @@ void guac_rdpdr_fs_process_set_rename_info(guac_rdp_common_svc* svc,
Stream_Seek_UINT8(input_stream); /* RootDirectory */ Stream_Seek_UINT8(input_stream); /* RootDirectory */
Stream_Read_UINT32(input_stream, filename_length); /* FileNameLength */ Stream_Read_UINT32(input_stream, filename_length); /* FileNameLength */
if (Stream_GetRemainingLength(input_stream) < filename_length) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Set "
"Information Request (FileRenameInformation) PDU does not "
"contain the expected number of bytes. File redirection "
"may not work as expected.");
return;
}
/* Convert name to UTF-8 */ /* Convert name to UTF-8 */
guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream), filename_length/2, guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream), filename_length/2,
destination_path, sizeof(destination_path)); destination_path, sizeof(destination_path));
@ -200,6 +209,15 @@ void guac_rdpdr_fs_process_set_allocation_info(guac_rdp_common_svc* svc,
UINT64 size; UINT64 size;
wStream* output_stream; wStream* output_stream;
/* Check to make sure the stream has at least 8 bytes (UINT64) */
if (Stream_GetRemainingLength(input_stream) < 8) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Set "
"Information Request (FileAllocationInformation) PDU does not "
"contain the expected number of bytes. File redirection "
"may not work as expected.");
return;
}
/* Read new size */ /* Read new size */
Stream_Read_UINT64(input_stream, size); /* AllocationSize */ Stream_Read_UINT64(input_stream, size); /* AllocationSize */
@ -252,6 +270,15 @@ void guac_rdpdr_fs_process_set_end_of_file_info(guac_rdp_common_svc* svc,
UINT64 size; UINT64 size;
wStream* output_stream; wStream* output_stream;
/* Check to make sure stream contains at least 8 bytes (UINT64) */
if (Stream_GetRemainingLength(input_stream) < 8) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Set "
"Information Request (FileEndOfFileInformation) PDU does not "
"contain the expected number of bytes. File redirection "
"may not work as expected.");
return;
}
/* Read new size */ /* Read new size */
Stream_Read_UINT64(input_stream, size); /* AllocationSize */ Stream_Read_UINT64(input_stream, size); /* AllocationSize */

View File

@ -50,9 +50,9 @@ void guac_rdpdr_fs_process_create(guac_rdp_common_svc* svc,
/* Check remaining stream data prior to reading. */ /* Check remaining stream data prior to reading. */
if (Stream_GetRemainingLength(input_stream) < 32) { if (Stream_GetRemainingLength(input_stream) < 32) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Create Drive "
"contain the expected number of bytes. File sharing may not " "Request PDU does not contain the expected number of bytes. "
"work as expected."); "Drive redirection may not work as expected.");
return; return;
} }
@ -65,6 +65,14 @@ void guac_rdpdr_fs_process_create(guac_rdp_common_svc* svc,
Stream_Read_UINT32(input_stream, create_options); Stream_Read_UINT32(input_stream, create_options);
Stream_Read_UINT32(input_stream, path_length); Stream_Read_UINT32(input_stream, path_length);
/* Check to make sure the stream contains path_length bytes. */
if(Stream_GetRemainingLength(input_stream) < path_length) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Create Drive "
"Request PDU does not contain the expected number of bytes. "
"Drive redirection may not work as expected.");
return;
}
/* Convert path to UTF-8 */ /* Convert path to UTF-8 */
guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream), path_length/2 - 1, guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream), path_length/2 - 1,
path, sizeof(path)); path, sizeof(path));
@ -133,9 +141,9 @@ void guac_rdpdr_fs_process_read(guac_rdp_common_svc* svc,
/* Check remaining bytes before reading stream. */ /* Check remaining bytes before reading stream. */
if (Stream_GetRemainingLength(input_stream) < 12) { if (Stream_GetRemainingLength(input_stream) < 12) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Read "
"contain the expected number of bytes. File sharing may not " "Request PDU does not contain the expected number of bytes. "
"work as expected."); "Drive redirection may not work as expected.");
return; return;
} }
@ -190,9 +198,9 @@ void guac_rdpdr_fs_process_write(guac_rdp_common_svc* svc,
/* Check remaining length. */ /* Check remaining length. */
if (Stream_GetRemainingLength(input_stream) < 32) { if (Stream_GetRemainingLength(input_stream) < 32) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Write "
"contain the expected number of bytes. File sharing may not " "Request PDU does not contain the expected number of bytes. "
"work as expected."); "Drive redirection may not work as expected.");
return; return;
} }
@ -205,6 +213,14 @@ void guac_rdpdr_fs_process_write(guac_rdp_common_svc* svc,
"%s: [file_id=%i] length=%i, offset=%" PRIu64, "%s: [file_id=%i] length=%i, offset=%" PRIu64,
__func__, iorequest->file_id, length, (uint64_t) offset); __func__, iorequest->file_id, length, (uint64_t) offset);
/* Check to make sure stream contains at least length bytes */
if (Stream_GetRemainingLength(input_stream) < length) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Write "
"Request PDU does not contain the expected number of bytes. "
"Drive redirection may not work as expected.");
return;
}
/* Attempt write */ /* Attempt write */
bytes_written = guac_rdp_fs_write((guac_rdp_fs*) device->data, bytes_written = guac_rdp_fs_write((guac_rdp_fs*) device->data,
iorequest->file_id, offset, Stream_Pointer(input_stream), length); iorequest->file_id, offset, Stream_Pointer(input_stream), length);
@ -270,9 +286,9 @@ void guac_rdpdr_fs_process_volume_info(guac_rdp_common_svc* svc,
/* Check remaining length */ /* Check remaining length */
if (Stream_GetRemainingLength(input_stream) < 4) { if (Stream_GetRemainingLength(input_stream) < 4) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Query "
"contain the expected number of bytes. File sharing may not " "Volume Information PDU does not contain the expected number "
"work as expected."); "of bytes. Drive redirection may not work as expected.");
return; return;
} }
@ -316,9 +332,9 @@ void guac_rdpdr_fs_process_file_info(guac_rdp_common_svc* svc,
/* Check remaining length */ /* Check remaining length */
if (Stream_GetRemainingLength(input_stream) < 4) { if (Stream_GetRemainingLength(input_stream) < 4) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Query "
"contain the expected number of bytes. File sharing may not " "Information PDU does not contain the expected number of "
"work as expected."); "bytes. Drive redirection may not work as expected.");
return; return;
} }
@ -370,9 +386,9 @@ void guac_rdpdr_fs_process_set_file_info(guac_rdp_common_svc* svc,
/* Check remaining length */ /* Check remaining length */
if (Stream_GetRemainingLength(input_stream) < 32) { if (Stream_GetRemainingLength(input_stream) < 32) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Set "
"contain the expected number of bytes. File sharing may not " "Information PDU does not contain the expected number of "
"work as expected."); "bytes. Drive redirection may not work as expected.");
return; return;
} }
@ -455,9 +471,9 @@ void guac_rdpdr_fs_process_query_directory(guac_rdp_common_svc* svc,
return; return;
if (Stream_GetRemainingLength(input_stream) < 9) { if (Stream_GetRemainingLength(input_stream) < 9) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Query "
"contain the expected number of bytes. File sharing may not " "Directory PDU does not contain the expected number of bytes. "
"work as expected."); "Drive redirection may not work as expected.");
return; return;
} }
@ -473,15 +489,15 @@ void guac_rdpdr_fs_process_query_directory(guac_rdp_common_svc* svc,
* Check to make sure Stream has at least the 23 padding bytes in it * Check to make sure Stream has at least the 23 padding bytes in it
* prior to seeking. * prior to seeking.
*/ */
if (Stream_GetRemainingLength(input_stream) < 23) { if (Stream_GetRemainingLength(input_stream) < (23 + path_length)) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "File stream does " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Drive Query "
"not contain the expected number of bytes. File sharing " "Directory PDU does not contain the expected number of "
"may not work as expected."); "bytes. Drive redirection may not work as expected.");
return; return;
} }
Stream_Seek(input_stream, 23); /* Padding */ Stream_Seek(input_stream, 23); /* Padding */
/* Convert path to UTF-8 */ /* Convert path to UTF-8 */
guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream), path_length/2 - 1, guac_rdp_utf16_to_utf8(Stream_Pointer(input_stream), path_length/2 - 1,
file->dir_pattern, sizeof(file->dir_pattern)); file->dir_pattern, sizeof(file->dir_pattern));

View File

@ -249,9 +249,9 @@ void guac_rdpdr_process_device_reply(guac_rdp_common_svc* svc,
/* Stream should contain at least 8 bytes (UINT32 + UINT32 ) */ /* Stream should contain at least 8 bytes (UINT32 + UINT32 ) */
if (Stream_GetRemainingLength(input_stream) < 8) { if (Stream_GetRemainingLength(input_stream) < 8) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Device Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Device Announce"
"contain the expected number of bytes. Device redirection may " "Response PDU does not contain the expected number of bytes."
"not work."); "Device redirection may not work as expected.");
return; return;
} }
@ -292,9 +292,9 @@ void guac_rdpdr_process_device_iorequest(guac_rdp_common_svc* svc,
/* Check to make sure the Stream contains at least 20 bytes (5 x UINT32 ). */ /* Check to make sure the Stream contains at least 20 bytes (5 x UINT32 ). */
if (Stream_GetRemainingLength(input_stream) < 20) { if (Stream_GetRemainingLength(input_stream) < 20) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Device Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Device I/O Request PDU "
"contain the expected number of bytes. Device redirection may " "does not contain the expected number of bytes. Device "
"not work as expected."); "redirection may not work as expected.");
return; return;
} }
@ -328,9 +328,9 @@ void guac_rdpdr_process_server_capability(guac_rdp_common_svc* svc,
/* Check to make sure the Stream has at least 4 bytes (UINT16 + 2) */ /* Check to make sure the Stream has at least 4 bytes (UINT16 + 2) */
if (Stream_GetRemainingLength(input_stream) < 4) { if (Stream_GetRemainingLength(input_stream) < 4) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Redirection Stream " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Core Capability "
"does not contain the expected number of bytes. Device " "Request PDU does not contain the expected number of bytes."
"redirection may not work as expected."); "Device redirection may not work as expected.");
return; return;
} }
@ -346,9 +346,10 @@ void guac_rdpdr_process_server_capability(guac_rdp_common_svc* svc,
/* Make sure Stream has at least 4 bytes (UINT16 + UINT16) */ /* Make sure Stream has at least 4 bytes (UINT16 + UINT16) */
if (Stream_GetRemainingLength(input_stream) < 4) { if (Stream_GetRemainingLength(input_stream) < 4) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Redirection Stream " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Core "
"does not contain the expected number of bytes. Device " "Capability Request PDU does not contain the expected "
"redirection may not work as expected."); "number of bytes. Device redirection may not work as "
"expected.");
break; break;
} }
@ -357,9 +358,10 @@ void guac_rdpdr_process_server_capability(guac_rdp_common_svc* svc,
/* Make sure Stream has required length remaining for Seek below. */ /* Make sure Stream has required length remaining for Seek below. */
if (Stream_GetRemainingLength(input_stream) < (length - 4)) { if (Stream_GetRemainingLength(input_stream) < (length - 4)) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Redirection Stream " guac_client_log(svc->client, GUAC_LOG_WARNING, "Server Core "
"does not contain the expected number of bytes. Device " "Capability Request PDU does not contain the expected "
"redirection may not work as expected."); "number of bytes. Device redirection may not work as "
"expected.");
break; break;
} }

View File

@ -69,9 +69,9 @@ void guac_rdpdr_process_print_job_write(guac_rdp_common_svc* svc,
/* Verify that Stream contains at least 32 bytes (UINT32 + 8 + 20) */ /* Verify that Stream contains at least 32 bytes (UINT32 + 8 + 20) */
if (Stream_GetRemainingLength(input_stream) < 32) { if (Stream_GetRemainingLength(input_stream) < 32) {
guac_client_log(client, GUAC_LOG_WARNING, "Printer Stream does not " guac_client_log(client, GUAC_LOG_WARNING, "Print job write stream does "
"contain the required number of bytes. Print redirection may " "not contain the expected number of bytes. Printer redirection "
"not work as expected."); "may not work as expected.");
return; return;
} }
@ -81,6 +81,14 @@ void guac_rdpdr_process_print_job_write(guac_rdp_common_svc* svc,
Stream_Seek(input_stream, 20); /* Padding */ Stream_Seek(input_stream, 20); /* Padding */
buffer = Stream_Pointer(input_stream); buffer = Stream_Pointer(input_stream);
/* Verify the stream has at least length number of bytes remaining. */
if (Stream_GetRemainingLength(input_stream) < length) {
guac_client_log(client, GUAC_LOG_WARNING, "Print job write stream does "
"not contain the expected number of bytes. Printer redirection "
"may not work as expected.");
return;
}
/* Write data only if job exists, translating status for RDP */ /* Write data only if job exists, translating status for RDP */
if (job != NULL && (length = guac_rdp_print_job_write(job, if (job != NULL && (length = guac_rdp_print_job_write(job,
buffer, length)) >= 0) { buffer, length)) >= 0) {

View File

@ -44,8 +44,8 @@ void guac_rdpdr_process_receive(guac_rdp_common_svc* svc,
*/ */
if (Stream_GetRemainingLength(input_stream) < 4) { if (Stream_GetRemainingLength(input_stream) < 4) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Device redirection " guac_client_log(svc->client, GUAC_LOG_WARNING, "Device redirection "
"Stream does not contain the required number of bytes. Device " "channel receive Stream does not contain the expected number "
"redirection may not function as expected."); "of bytes. Device redirection may not function as expected.");
return; return;
} }

View File

@ -52,9 +52,9 @@ void guac_rdpsnd_formats_handler(guac_rdp_common_svc* svc,
/* Check to make sure the stream has at least 20 bytes, which */ /* Check to make sure the stream has at least 20 bytes, which */
if (Stream_GetRemainingLength(input_stream) < 20) { if (Stream_GetRemainingLength(input_stream) < 20) {
guac_client_log(client, GUAC_LOG_WARNING, "Audio Stream does not " guac_client_log(client, GUAC_LOG_WARNING, "Server Audio Formats and "
"contain the expected number of bytes. Sound may not work as " "Version PDU does not contain the expected number of bytes. "
"expected."); "Audio redirection may not work as expected.");
return; return;
} }
@ -106,9 +106,10 @@ void guac_rdpsnd_formats_handler(guac_rdp_common_svc* svc,
/* Check to make sure Stream has at least 18 bytes. */ /* Check to make sure Stream has at least 18 bytes. */
if (Stream_GetRemainingLength(input_stream) < 18) { if (Stream_GetRemainingLength(input_stream) < 18) {
guac_client_log(client, GUAC_LOG_WARNING, "Audio Stream does " guac_client_log(client, GUAC_LOG_WARNING, "Server Audio "
"not contain the expected number of bytes. Sound may " "Formats and Version PDU does not contain the expected "
"not work as expected."); "number of bytes. Audio redirection may not work as "
"expected.");
return; return;
} }
@ -125,9 +126,10 @@ void guac_rdpsnd_formats_handler(guac_rdp_common_svc* svc,
/* Check that Stream has at least body_size bytes remaining. */ /* Check that Stream has at least body_size bytes remaining. */
if (Stream_GetRemainingLength(input_stream) < body_size) { if (Stream_GetRemainingLength(input_stream) < body_size) {
guac_client_log(client, GUAC_LOG_WARNING, "Audio Stream does " guac_client_log(client, GUAC_LOG_WARNING, "Server Audio "
"not contain the expected number of bytes. Sound may " "Formats and Version PDU does not contain the expected "
"not work as expected."); "number of bytes. Audio redirection may not work as "
"expected.");
return; return;
} }
@ -232,9 +234,9 @@ void guac_rdpsnd_training_handler(guac_rdp_common_svc* svc,
/* Check to make sure audio stream contains a minimum number of bytes. */ /* Check to make sure audio stream contains a minimum number of bytes. */
if (Stream_GetRemainingLength(input_stream) < 4) { if (Stream_GetRemainingLength(input_stream) < 4) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Audio Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Audio Training PDU "
"contain the expected number of bytes. Sound may not work as " "does not contain the expected number of bytes. Audio "
"expected."); "redirection may not work as expected.");
return; return;
} }
@ -267,9 +269,9 @@ void guac_rdpsnd_wave_info_handler(guac_rdp_common_svc* svc,
/* Check to make sure audio stream contains a minimum number of bytes. */ /* Check to make sure audio stream contains a minimum number of bytes. */
if (Stream_GetRemainingLength(input_stream) < 12) { if (Stream_GetRemainingLength(input_stream) < 12) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Audio stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Audio WaveInfo PDU "
"contain the expected number of bytes. Sound may not work as " "does not contain the expected number of bytes. Sound may not "
"expected."); "work as expected.");
return; return;
} }
@ -310,9 +312,9 @@ void guac_rdpsnd_wave_handler(guac_rdp_common_svc* svc,
/* Verify we have at least 4 bytes, which is manually copied below. */ /* Verify we have at least 4 bytes, which is manually copied below. */
if (Stream_Length(input_stream) < 4) { if (Stream_Length(input_stream) < 4) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Sound stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Audio Wave PDU does "
"contain the expected number of bytes. Sound may not work as " "not contain the expected number of bytes. Sound may not work "
"expected."); "as expected.");
return; return;
} }

View File

@ -38,8 +38,8 @@ void guac_rdpsnd_process_receive(guac_rdp_common_svc* svc,
/* Check that we at least the 4 byte header (UINT8 + UINT8 + UINT16) */ /* Check that we at least the 4 byte header (UINT8 + UINT8 + UINT16) */
if (Stream_GetRemainingLength(input_stream) < 4) { if (Stream_GetRemainingLength(input_stream) < 4) {
guac_client_log(svc->client, GUAC_LOG_WARNING, "Audio Stream does not " guac_client_log(svc->client, GUAC_LOG_WARNING, "Audio Stream does not "
"contain the expected number of bytes. Sound may not work as " "contain the expected number of bytes. Audio redirection may "
"expected."); "not work as expected.");
return; return;
} }

View File

@ -239,9 +239,9 @@ void guac_rdp_ai_process_version(guac_client* client,
/* Verify we have at least 4 bytes available (UINT32) */ /* Verify we have at least 4 bytes available (UINT32) */
if (Stream_GetRemainingLength(stream) < 4) { if (Stream_GetRemainingLength(stream) < 4) {
guac_client_log(client, GUAC_LOG_WARNING, "Audio input stream does not " guac_client_log(client, GUAC_LOG_WARNING, "Audio input Versoin PDU "
"contain the expected number of bytes. Audio input may not " "does not contain the expected number of bytes. Audio input "
"work as expected."); "redirection may not work as expected.");
return; return;
} }
@ -273,9 +273,9 @@ void guac_rdp_ai_process_formats(guac_client* client,
/* Verify we have at least 8 bytes available (2 x UINT32) */ /* Verify we have at least 8 bytes available (2 x UINT32) */
if (Stream_GetRemainingLength(stream) < 8) { if (Stream_GetRemainingLength(stream) < 8) {
guac_client_log(client, GUAC_LOG_WARNING, "Audio input stream does not " guac_client_log(client, GUAC_LOG_WARNING, "Audio input Sound Formats "
"contain the expected number of bytes. Audio input may not " "PDU does not contain the expected number of bytes. Audio "
"work as expected."); "input redirection may not work as expected.");
return; return;
} }
@ -329,9 +329,9 @@ void guac_rdp_ai_process_open(guac_client* client,
/* Verify we have at least 8 bytes available (2 x UINT32) */ /* Verify we have at least 8 bytes available (2 x UINT32) */
if (Stream_GetRemainingLength(stream) < 8) { if (Stream_GetRemainingLength(stream) < 8) {
guac_client_log(client, GUAC_LOG_WARNING, "Audio input stream does not " guac_client_log(client, GUAC_LOG_WARNING, "Audio input Open PDU does "
"contain the expected number of bytes. Audio input may not " "not contain the expected number of bytes. Audio input "
"work as expected."); "redirection may not work as expected.");
return; return;
} }

View File

@ -55,8 +55,8 @@ static void guac_rdp_ai_handle_data(guac_client* client,
/* Verify we have at least 1 byte in the stream (UINT8) */ /* Verify we have at least 1 byte in the stream (UINT8) */
if (Stream_GetRemainingLength(stream) < 1) { if (Stream_GetRemainingLength(stream) < 1) {
guac_client_log(client, GUAC_LOG_WARNING, "Audio input stream does not " guac_client_log(client, GUAC_LOG_WARNING, "Audio input stream does not "
"contain the expected number of bytes. Audio input may not " "contain the expected number of bytes. Audio input redirection "
"work as expected."); "may not work as expected.");
return; return;
} }