apptrace: Adds checks for user arguments in apptrace API

This commit is contained in:
Alexey Gerenkov 2018-12-26 15:42:07 +03:00
parent c0f37a324e
commit 2d52ac48f9
2 changed files with 32 additions and 1 deletions

View file

@ -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);

View file

@ -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,