aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/win/process.c15
-rw-r--r--test/test-list.h2
-rw-r--r--test/test-signal.c20
3 files changed, 35 insertions, 2 deletions
diff --git a/src/win/process.c b/src/win/process.c
index 764250e1..cc06d9e2 100644
--- a/src/win/process.c
+++ b/src/win/process.c
@@ -1173,6 +1173,10 @@ int uv_spawn(uv_loop_t* loop,
static int uv__kill(HANDLE process_handle, int signum) {
+ if (signum < 0 || signum >= NSIG) {
+ return UV_EINVAL;
+ }
+
switch (signum) {
case SIGTERM:
case SIGKILL:
@@ -1237,8 +1241,15 @@ int uv_process_kill(uv_process_t* process, int signum) {
int uv_kill(int pid, int signum) {
int err;
- HANDLE process_handle = OpenProcess(PROCESS_TERMINATE |
- PROCESS_QUERY_INFORMATION, FALSE, pid);
+ HANDLE process_handle;
+
+ if (pid == 0) {
+ process_handle = GetCurrentProcess();
+ } else {
+ process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
+ FALSE,
+ pid);
+ }
if (process_handle == NULL) {
err = GetLastError();
diff --git a/test/test-list.h b/test/test-list.h
index bc75858f..892a0019 100644
--- a/test/test-list.h
+++ b/test/test-list.h
@@ -266,6 +266,7 @@ TEST_DECLARE (spawn_tcp_server)
TEST_DECLARE (fs_poll)
TEST_DECLARE (fs_poll_getpath)
TEST_DECLARE (kill)
+TEST_DECLARE (kill_invalid_signum)
TEST_DECLARE (fs_file_noent)
TEST_DECLARE (fs_file_nametoolong)
TEST_DECLARE (fs_file_loop)
@@ -756,6 +757,7 @@ TASK_LIST_START
TEST_ENTRY (fs_poll)
TEST_ENTRY (fs_poll_getpath)
TEST_ENTRY (kill)
+ TEST_ENTRY (kill_invalid_signum)
TEST_ENTRY (poll_close_doesnt_corrupt_stack)
TEST_ENTRY (poll_closesocket)
diff --git a/test/test-signal.c b/test/test-signal.c
index 9a881510..c2ce5ec0 100644
--- a/test/test-signal.c
+++ b/test/test-signal.c
@@ -22,6 +22,26 @@
#include "uv.h"
#include "task.h"
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+TEST_IMPL(kill_invalid_signum) {
+ uv_pid_t pid;
+
+ pid = uv_os_getpid();
+
+ ASSERT(uv_kill(pid, -1) == UV_EINVAL);
+#ifdef _WIN32
+ /* NSIG is not available on all platforms. */
+ ASSERT(uv_kill(pid, NSIG) == UV_EINVAL);
+#endif
+ ASSERT(uv_kill(pid, 4096) == UV_EINVAL);
+
+ MAKE_VALGRIND_HAPPY();
+ return 0;
+}
+
/* For Windows we test only signum handling */
#ifdef _WIN32
static void signum_test_cb(uv_signal_t* handle, int signum) {