diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c index 58fc7eb4..e5069424 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.c @@ -422,3 +422,16 @@ int guac_rdpdr_fs_convert_path(const char* parent, const char* rel_path, char* a } +guac_rdpdr_fs_file* guac_rdpdr_fs_get_file(guac_rdpdr_device* device, + int file_id) { + + /* Validate ID */ + guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data; + if (file_id < 0 || file_id >= GUAC_RDPDR_FS_MAX_FILES) + return NULL; + + /* Return file at given ID */ + return &(data->files[file_id]); + +} + diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h index bc7b025a..23d7d8a7 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs.h @@ -258,5 +258,11 @@ int guac_rdpdr_fs_convert_path(const char* parent, const char* rel_path, char* a */ const char* guac_rdpdr_fs_read_dir(guac_rdpdr_device* device, int file_id); +/** + * Returns the file having the given ID, or NULL if no such file exists. + */ +guac_rdpdr_fs_file* guac_rdpdr_fs_get_file(guac_rdpdr_device* device, + int file_id); + #endif diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages.c index bfa3f673..270ee173 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages.c @@ -292,13 +292,17 @@ void guac_rdpdr_fs_process_query_directory(guac_rdpdr_device* device, wStream* i wStream* output_stream; - guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data; - guac_rdpdr_fs_file* file = &(data->files[file_id]); + guac_rdpdr_fs_file* file; int fs_information_class, initial_query; int path_length; const char* entry_name; + /* Get file */ + file = guac_rdpdr_fs_get_file(device, file_id); + if (file == NULL) + return; + /* Read main header */ Stream_Read_UINT32(input_stream, fs_information_class); Stream_Read_UINT8(input_stream, initial_query); diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_dir_info.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_dir_info.c index c03daa41..41a56cda 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_dir_info.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_dir_info.c @@ -63,8 +63,7 @@ void guac_rdpdr_fs_process_query_full_directory_info(guac_rdpdr_device* device, void guac_rdpdr_fs_process_query_both_directory_info(guac_rdpdr_device* device, const char* entry_name, int file_id, int completion_id) { - guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data; - guac_rdpdr_fs_file* file = &(data->files[file_id]); + guac_rdpdr_fs_file* file; wStream* output_stream = Stream_New(NULL, 256); int length = guac_utf8_strlen(entry_name); @@ -73,6 +72,11 @@ void guac_rdpdr_fs_process_query_both_directory_info(guac_rdpdr_device* device, unsigned char utf16_entry_name[256]; guac_rdp_utf8_to_utf16((const unsigned char*) entry_name, (char*) utf16_entry_name, length); + /* Get file */ + file = guac_rdpdr_fs_get_file(device, file_id); + if (file == NULL) + return; + /* Write header */ Stream_Write_UINT16(output_stream, RDPDR_CTYP_CORE); Stream_Write_UINT16(output_stream, PAKID_CORE_DEVICE_IOCOMPLETION); diff --git a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_file_info.c b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_file_info.c index 30da8507..876f442c 100644 --- a/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_file_info.c +++ b/src/protocols/rdp/guac_rdpdr/rdpdr_fs_messages_file_info.c @@ -56,8 +56,12 @@ void guac_rdpdr_fs_process_query_basic_info(guac_rdpdr_device* device, wStream* int file_id, int completion_id) { wStream* output_stream = Stream_New(NULL, 60); - guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data; - guac_rdpdr_fs_file* file = &(data->files[file_id]); + guac_rdpdr_fs_file* file; + + /* Get file */ + file = guac_rdpdr_fs_get_file(device, file_id); + if (file == NULL) + return; /* Write header */ Stream_Write_UINT16(output_stream, RDPDR_CTYP_CORE); @@ -85,10 +89,14 @@ void guac_rdpdr_fs_process_query_standard_info(guac_rdpdr_device* device, wStrea int file_id, int completion_id) { wStream* output_stream = Stream_New(NULL, 60); - guac_rdpdr_fs_data* data = (guac_rdpdr_fs_data*) device->data; - guac_rdpdr_fs_file* file = &(data->files[file_id]); - + guac_rdpdr_fs_file* file; BOOL is_directory = FALSE; + + /* Get file */ + file = guac_rdpdr_fs_get_file(device, file_id); + if (file == NULL) + return; + if (file->attributes & FILE_ATTRIBUTE_DIRECTORY) is_directory = TRUE;