From 7ff52b836db74379d306447ccf66b3c069d3f1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 4 Sep 2014 14:17:59 +0200 Subject: [PATCH] unix, windows: don't allow a NULL callback on timers --- src/unix/timer.c | 3 +++ src/win/timer.c | 3 +++ test/test-list.h | 2 ++ test/test-timer.c | 11 +++++++++++ 4 files changed, 19 insertions(+) diff --git a/src/unix/timer.c b/src/unix/timer.c index 9bd0423b..ca3ec3db 100644 --- a/src/unix/timer.c +++ b/src/unix/timer.c @@ -65,6 +65,9 @@ int uv_timer_start(uv_timer_t* handle, uint64_t repeat) { uint64_t clamped_timeout; + if (cb == NULL) + return -EINVAL; + if (uv__is_active(handle)) uv_timer_stop(handle); diff --git a/src/win/timer.c b/src/win/timer.c index 6c49d11b..dcd2d478 100644 --- a/src/win/timer.c +++ b/src/win/timer.c @@ -119,6 +119,9 @@ int uv_timer_start(uv_timer_t* handle, uv_timer_cb timer_cb, uint64_t timeout, uv_loop_t* loop = handle->loop; uv_timer_t* old; + if (timer_cb == NULL) + return UV_EINVAL; + if (handle->flags & UV_HANDLE_ACTIVE) { RB_REMOVE(uv_timer_tree_s, &loop->timers, handle); } diff --git a/test/test-list.h b/test/test-list.h index 9d51da9a..4d1d5db2 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -133,6 +133,7 @@ TEST_DECLARE (timer_huge_timeout) TEST_DECLARE (timer_huge_repeat) TEST_DECLARE (timer_run_once) TEST_DECLARE (timer_from_check) +TEST_DECLARE (timer_null_callback) TEST_DECLARE (idle_starvation) TEST_DECLARE (loop_handles) TEST_DECLARE (get_loadavg) @@ -451,6 +452,7 @@ TASK_LIST_START TEST_ENTRY (timer_huge_repeat) TEST_ENTRY (timer_run_once) TEST_ENTRY (timer_from_check) + TEST_ENTRY (timer_null_callback) TEST_ENTRY (idle_starvation) diff --git a/test/test-timer.c b/test/test-timer.c index f26dae57..aba050fd 100644 --- a/test/test-timer.c +++ b/test/test-timer.c @@ -290,3 +290,14 @@ TEST_IMPL(timer_run_once) { MAKE_VALGRIND_HAPPY(); return 0; } + + +TEST_IMPL(timer_null_callback) { + uv_timer_t handle; + + ASSERT(0 == uv_timer_init(uv_default_loop(), &handle)); + ASSERT(UV_EINVAL == uv_timer_start(&handle, NULL, 100, 100)); + + MAKE_VALGRIND_HAPPY(); + return 0; +}