From 727ffbe90863dc1cf69ff7f2abc6a568df35168e Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 16 Aug 2019 13:00:21 +1000 Subject: [PATCH] esp_timer: Add parameter NULL checks to public API Return ESP_ERR_INVALID_ARG if the handle is NULL, instead of crashing. As reported via forum https://esp32.com/viewtopic.php?f=13&t=11721&p=47926#p47926 --- components/esp_common/src/esp_timer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/esp_common/src/esp_timer.c b/components/esp_common/src/esp_timer.c index 034f77fcc..718b8100d 100644 --- a/components/esp_common/src/esp_timer.c +++ b/components/esp_common/src/esp_timer.c @@ -104,7 +104,7 @@ esp_err_t esp_timer_create(const esp_timer_create_args_t* args, if (!is_initialized()) { return ESP_ERR_INVALID_STATE; } - if (args->callback == NULL) { + if (args == NULL || args->callback == NULL || out_handle == NULL) { return ESP_ERR_INVALID_ARG; } esp_timer_handle_t result = (esp_timer_handle_t) calloc(1, sizeof(*result)); @@ -123,6 +123,9 @@ esp_err_t esp_timer_create(const esp_timer_create_args_t* args, esp_err_t IRAM_ATTR esp_timer_start_once(esp_timer_handle_t timer, uint64_t timeout_us) { + if (timer == NULL) { + return ESP_ERR_INVALID_ARG; + } if (!is_initialized() || timer_armed(timer)) { return ESP_ERR_INVALID_STATE; } @@ -136,6 +139,9 @@ esp_err_t IRAM_ATTR esp_timer_start_once(esp_timer_handle_t timer, uint64_t time esp_err_t IRAM_ATTR esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t period_us) { + if (timer == NULL) { + return ESP_ERR_INVALID_ARG; + } if (!is_initialized() || timer_armed(timer)) { return ESP_ERR_INVALID_STATE; } @@ -150,6 +156,9 @@ esp_err_t IRAM_ATTR esp_timer_start_periodic(esp_timer_handle_t timer, uint64_t esp_err_t IRAM_ATTR esp_timer_stop(esp_timer_handle_t timer) { + if (timer == NULL) { + return ESP_ERR_INVALID_ARG; + } if (!is_initialized() || !timer_armed(timer)) { return ESP_ERR_INVALID_STATE; }