From 2d52ac48f921be984b724b7d85767a7eb2252149 Mon Sep 17 00:00:00 2001 From: Alexey Gerenkov Date: Wed, 26 Dec 2018 15:42:07 +0300 Subject: [PATCH] apptrace: Adds checks for user arguments in apptrace API --- components/app_trace/app_trace.c | 22 +++++++++++++++++++++- components/app_trace/host_file_io.c | 11 +++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/components/app_trace/app_trace.c b/components/app_trace/app_trace.c index 445e0f7c2f..84e39d7b16 100644 --- a/components/app_trace/app_trace.c +++ b/components/app_trace/app_trace.c @@ -929,6 +929,9 @@ esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *buf, uint32_t *size, ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!"); return ESP_ERR_NOT_SUPPORTED; } + if (buf == NULL || size == NULL || *size == 0) { + return ESP_ERR_INVALID_ARG; + } //TODO: callback system esp_apptrace_tmo_init(&tmo, user_tmo); @@ -963,8 +966,10 @@ uint8_t *esp_apptrace_down_buffer_get(esp_apptrace_dest_t dest, uint32_t *size, ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!"); return NULL; } + if (size == NULL || *size == 0) { + return NULL; + } - // ESP_APPTRACE_LOGE("esp_apptrace_down_buffer_get %d", *size); esp_apptrace_tmo_init(&tmo, user_tmo); return hw->get_down_buffer(size, &tmo); } @@ -985,6 +990,9 @@ esp_err_t esp_apptrace_down_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, u ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!"); return ESP_ERR_NOT_SUPPORTED; } + if (ptr == NULL) { + return ESP_ERR_INVALID_ARG; + } esp_apptrace_tmo_init(&tmo, user_tmo); return hw->put_down_buffer(ptr, &tmo); @@ -1007,6 +1015,9 @@ esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, uint32_ ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!"); return ESP_ERR_NOT_SUPPORTED; } + if (data == NULL || size == 0) { + return ESP_ERR_INVALID_ARG; + } esp_apptrace_tmo_init(&tmo, user_tmo); ptr = hw->get_up_buffer(size, &tmo); @@ -1040,6 +1051,9 @@ int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t user_tmo, const c ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!"); return ESP_ERR_NOT_SUPPORTED; } + if (fmt == NULL) { + return ESP_ERR_INVALID_ARG; + } esp_apptrace_tmo_init(&tmo, user_tmo); ESP_APPTRACE_LOGD("fmt %x", fmt); @@ -1101,6 +1115,9 @@ uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, uint32_t size, uint32 ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!"); return NULL; } + if (size == 0) { + return NULL; + } esp_apptrace_tmo_init(&tmo, user_tmo); return hw->get_up_buffer(size, &tmo); @@ -1122,6 +1139,9 @@ esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32 ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!"); return ESP_ERR_NOT_SUPPORTED; } + if (ptr == NULL) { + return ESP_ERR_INVALID_ARG; + } esp_apptrace_tmo_init(&tmo, user_tmo); return hw->put_up_buffer(ptr, &tmo); diff --git a/components/app_trace/host_file_io.c b/components/app_trace/host_file_io.c index b818440145..b59b837aa2 100644 --- a/components/app_trace/host_file_io.c +++ b/components/app_trace/host_file_io.c @@ -145,6 +145,9 @@ void *esp_apptrace_fopen(esp_apptrace_dest_t dest, const char *path, const char esp_apptrace_fopen_args_t cmd_args; ESP_EARLY_LOGV(TAG, "esp_apptrace_fopen '%s' '%s'", path, mode); + if (path == NULL || mode == NULL) { + return 0; + } cmd_args.path = path; cmd_args.path_len = strlen(path) + 1; @@ -213,6 +216,10 @@ size_t esp_apptrace_fwrite(esp_apptrace_dest_t dest, const void *ptr, size_t siz ESP_EARLY_LOGV(TAG, "esp_apptrace_fwrite f %p l %d", stream, size*nmemb); + if (ptr == NULL) { + return 0; + } + cmd_args.buf = (void *)ptr; cmd_args.size = size * nmemb; cmd_args.file = stream; @@ -248,6 +255,10 @@ size_t esp_apptrace_fread(esp_apptrace_dest_t dest, void *ptr, size_t size, size ESP_EARLY_LOGV(TAG, "esp_apptrace_fread f %p l %d", stream, size*nmemb); + if (ptr == NULL) { + return 0; + } + cmd_args.size = size * nmemb; cmd_args.file = stream; esp_err_t ret = esp_apptrace_file_cmd_send(dest, ESP_APPTRACE_FILE_CMD_FREAD, esp_apptrace_fread_args_prepare,