From aa4790352044cf1bc9c46ec6e9d91befc1427230 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 18 Jan 2017 17:53:25 +0100 Subject: [PATCH] Prevent 'dereference before null check' --- tasks/task_file_transfer.c | 104 +++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/tasks/task_file_transfer.c b/tasks/task_file_transfer.c index 51d75d39f0..ed1bbcf387 100644 --- a/tasks/task_file_transfer.c +++ b/tasks/task_file_transfer.c @@ -69,63 +69,67 @@ void task_file_load_handler(retro_task_t *task) { nbio_handle_t *nbio = (nbio_handle_t*)task->state; - switch (nbio->status) + if (nbio) { - case NBIO_STATUS_INIT: - if (nbio && !string_is_empty(nbio->path)) - { - const char *fullpath = nbio->path; - struct nbio_t *handle = nbio_open(fullpath, NBIO_READ); - if (handle) + switch (nbio->status) + { + case NBIO_STATUS_INIT: + if (nbio && !string_is_empty(nbio->path)) { - nbio->handle = handle; - nbio->status = NBIO_STATUS_TRANSFER; + const char *fullpath = nbio->path; + struct nbio_t *handle = nbio_open(fullpath, NBIO_READ); - if (strstr(fullpath, file_path_str(FILE_PATH_PNG_EXTENSION))) - nbio->image_type = IMAGE_TYPE_PNG; - else if (strstr(fullpath, file_path_str(FILE_PATH_JPEG_EXTENSION)) - || strstr(fullpath, file_path_str(FILE_PATH_JPG_EXTENSION))) - nbio->image_type = IMAGE_TYPE_JPEG; - else if (strstr(fullpath, file_path_str(FILE_PATH_BMP_EXTENSION))) - nbio->image_type = IMAGE_TYPE_BMP; - else if (strstr(fullpath, file_path_str(FILE_PATH_TGA_EXTENSION))) - nbio->image_type = IMAGE_TYPE_TGA; + if (handle) + { + nbio->handle = handle; + nbio->status = NBIO_STATUS_TRANSFER; - nbio_begin_read(handle); - return; + if (strstr(fullpath, file_path_str(FILE_PATH_PNG_EXTENSION))) + nbio->image_type = IMAGE_TYPE_PNG; + else if (strstr(fullpath, file_path_str(FILE_PATH_JPEG_EXTENSION)) + || strstr(fullpath, file_path_str(FILE_PATH_JPG_EXTENSION))) + nbio->image_type = IMAGE_TYPE_JPEG; + else if (strstr(fullpath, file_path_str(FILE_PATH_BMP_EXTENSION))) + nbio->image_type = IMAGE_TYPE_BMP; + else if (strstr(fullpath, file_path_str(FILE_PATH_TGA_EXTENSION))) + nbio->image_type = IMAGE_TYPE_TGA; + + nbio_begin_read(handle); + return; + } + else + task_set_cancelled(task, true); } - else + break; + case NBIO_STATUS_TRANSFER_PARSE: + if (task_file_transfer_iterate_parse(nbio) == -1) task_set_cancelled(task, true); - } - break; - case NBIO_STATUS_TRANSFER_PARSE: - if (task_file_transfer_iterate_parse(nbio) == -1) - task_set_cancelled(task, true); - nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE; - break; - case NBIO_STATUS_TRANSFER: - if (task_file_transfer_iterate_transfer(nbio) == -1) - nbio->status = NBIO_STATUS_TRANSFER_PARSE; - break; - case NBIO_STATUS_TRANSFER_PARSE_FREE: - case NBIO_STATUS_POLL: - default: - break; - } + nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE; + break; + case NBIO_STATUS_TRANSFER: + if (task_file_transfer_iterate_transfer(nbio) == -1) + nbio->status = NBIO_STATUS_TRANSFER_PARSE; + break; + case NBIO_STATUS_TRANSFER_PARSE_FREE: + case NBIO_STATUS_POLL: + default: + break; + } - switch (nbio->image_type) - { - case IMAGE_TYPE_PNG: - case IMAGE_TYPE_JPEG: - case IMAGE_TYPE_TGA: - case IMAGE_TYPE_BMP: - if (!task_image_load_handler(task)) - task_set_finished(task, true); - break; - case 0: - if (nbio->is_finished) - task_set_finished(task, true); - break; + switch (nbio->image_type) + { + case IMAGE_TYPE_PNG: + case IMAGE_TYPE_JPEG: + case IMAGE_TYPE_TGA: + case IMAGE_TYPE_BMP: + if (!task_image_load_handler(task)) + task_set_finished(task, true); + break; + case 0: + if (nbio->is_finished) + task_set_finished(task, true); + break; + } } if (task_get_cancelled(task))