Add ffunction for retrieving a file by file ID safely. Migrate to new function.
This commit is contained in:
parent
dd1761790a
commit
3217b97f26
@ -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]);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user