From b9d5396a4082b101051ece4f6e3c15a4d5bd7a98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Sat, 12 Apr 2014 10:09:40 +0200 Subject: [PATCH 1/4] windows: fix console signal handler refcount Backport of 0c726e7 from master --- src/win/signal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/win/signal.c b/src/win/signal.c index e630cd38..f2938355 100644 --- a/src/win/signal.c +++ b/src/win/signal.c @@ -129,8 +129,10 @@ static uv_err_t uv__signal_register_control_handler() { /* If the console control handler has already been hooked, just add a */ /* reference. */ - if (uv__signal_control_handler_refs > 0) + if (uv__signal_control_handler_refs > 0) { + uv__signal_control_handler_refs++; return uv_ok_; + } if (!SetConsoleCtrlHandler(uv__signal_control_handler, TRUE)) return uv__new_sys_error(GetLastError()); From d30e3ab65acf7b77945658d3e6127ca6af6eec6d Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sun, 13 Apr 2014 15:53:11 +0400 Subject: [PATCH 2/4] inet: allow scope in `uv_inet_pton` ip6 check Note that isn't actually parsing it, since the output value is a `struct in6_addr`. see https://github.com/joyent/node/issues/7395 --- build.mk | 1 + checksparse.sh | 1 + src/inet.c | 15 +++++++++-- test/test-ip6-addr.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ test/test-list.h | 2 ++ uv.gyp | 1 + 6 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 test/test-ip6-addr.c diff --git a/build.mk b/build.mk index e273e251..1b11b85c 100644 --- a/build.mk +++ b/build.mk @@ -87,6 +87,7 @@ TESTS= \ test/test-getsockname.o \ test/test-hrtime.o \ test/test-idle.o \ + test/test-ip6-addr.o \ test/test-ipc.o \ test/test-ipc-send-recv.o \ test/test-loop-handles.o \ diff --git a/checksparse.sh b/checksparse.sh index 01fac07a..a75039fc 100755 --- a/checksparse.sh +++ b/checksparse.sh @@ -107,6 +107,7 @@ test/test-getaddrinfo.c test/test-getsockname.c test/test-hrtime.c test/test-idle.c +test/test-ip6-addr.c test/test-ipc-send-recv.c test/test-ipc.c test/test-loop-handles.c diff --git a/src/inet.c b/src/inet.c index 8f9d89b0..d8848988 100644 --- a/src/inet.c +++ b/src/inet.c @@ -229,7 +229,7 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) { curtok = src; seen_xdigits = 0; val = 0; - while ((ch = *src++) != '\0') { + while ((ch = *src++) != '\0' && ch != '%') { const char *pch; if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) @@ -260,7 +260,18 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) { continue; } if (ch == '.' && ((tp + sizeof(struct in_addr)) <= endp)) { - uv_err_t err = inet_pton4(curtok, tp); + uv_err_t err; + + /* Scope id present, parse ipv4 addr without it */ + pch = strchr(curtok, '%'); + if (pch != NULL) { + char tmp[sizeof "255.255.255.255"]; + + memcpy(tmp, curtok, pch - curtok); + curtok = tmp; + src = pch; + } + err = inet_pton4(curtok, tp); if (err.code == 0) { tp += sizeof(struct in_addr); seen_xdigits = 0; diff --git a/test/test-ip6-addr.c b/test/test-ip6-addr.c new file mode 100644 index 00000000..3b4cb8fe --- /dev/null +++ b/test/test-ip6-addr.c @@ -0,0 +1,64 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "task.h" + +#define GOOD_ADDR_LIST(X) \ + X("::") \ + X("::1") \ + X("fe80::1") \ + X("fe80::") \ + X("fe80::2acf:daff:fedd:342a") \ + X("fe80:0:0:0:2acf:daff:fedd:342a") \ + X("fe80:0:0:0:2acf:daff:1.2.3.4") \ + +#define BAD_ADDR_LIST(X) \ + X(":::1") \ + X("abcde::1") \ + X("fe80:0:0:0:2acf:daff:fedd:342a:5678") \ + X("fe80:0:0:0:2acf:daff:abcd:1.2.3.4") \ + X("fe80:0:0:2acf:daff:1.2.3.4.5") \ + +#define TEST_GOOD(ADDR) \ + ASSERT(uv_inet_pton(AF_INET6, ADDR, &addr).code == UV_OK); \ + ASSERT(uv_inet_pton(AF_INET6, ADDR "%en1", &addr).code == UV_OK); \ + ASSERT(uv_inet_pton(AF_INET6, ADDR "%%%%", &addr).code == UV_OK); \ + ASSERT(uv_inet_pton(AF_INET6, ADDR "%en1:1.2.3.4", &addr).code == UV_OK); \ + +#define TEST_BAD(ADDR) \ + ASSERT(uv_inet_pton(AF_INET6, ADDR, &addr).code != UV_OK); \ + ASSERT(uv_inet_pton(AF_INET6, ADDR "%en1", &addr).code != UV_OK); \ + ASSERT(uv_inet_pton(AF_INET6, ADDR "%%%%", &addr).code != UV_OK); \ + ASSERT(uv_inet_pton(AF_INET6, ADDR "%en1:1.2.3.4", &addr).code != UV_OK); \ + +TEST_IMPL(ip6_pton) { + struct in6_addr addr; + + GOOD_ADDR_LIST(TEST_GOOD) + BAD_ADDR_LIST(TEST_BAD) + + MAKE_VALGRIND_HAPPY(); + return 0; +} + +#undef GOOD_ADDR_LIST +#undef BAD_ADDR_LIST diff --git a/test/test-list.h b/test/test-list.h index c280ca95..739de09b 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -37,6 +37,7 @@ TEST_DECLARE (semaphore_2) TEST_DECLARE (semaphore_3) TEST_DECLARE (tty) TEST_DECLARE (stdio_over_pipes) +TEST_DECLARE (ip6_pton) TEST_DECLARE (ipc_listen_before_write) TEST_DECLARE (ipc_listen_after_write) #ifndef _WIN32 @@ -265,6 +266,7 @@ TASK_LIST_START TEST_ENTRY (pipe_server_close) TEST_ENTRY (tty) TEST_ENTRY (stdio_over_pipes) + TEST_ENTRY (ip6_pton) TEST_ENTRY (ipc_listen_before_write) TEST_ENTRY (ipc_listen_after_write) #ifndef _WIN32 diff --git a/uv.gyp b/uv.gyp index 4e87dc1a..04c8e2da 100644 --- a/uv.gyp +++ b/uv.gyp @@ -305,6 +305,7 @@ 'test/test-getsockname.c', 'test/test-hrtime.c', 'test/test-idle.c', + 'test/test-ip6-addr.c', 'test/test-ipc.c', 'test/test-ipc-send-recv.c', 'test/test-list.h', From 23d130b2095f0e430683f2db40bf7f16ee8744cd Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Mon, 14 Apr 2014 15:13:20 +0400 Subject: [PATCH 3/4] Revert "inet: allow scope in `uv_inet_pton` ip6 check" This reverts commit d30e3ab65acf7b77945658d3e6127ca6af6eec6, because it is a new feature! --- build.mk | 1 - checksparse.sh | 1 - src/inet.c | 15 ++--------- test/test-ip6-addr.c | 64 -------------------------------------------- test/test-list.h | 2 -- uv.gyp | 1 - 6 files changed, 2 insertions(+), 82 deletions(-) delete mode 100644 test/test-ip6-addr.c diff --git a/build.mk b/build.mk index 1b11b85c..e273e251 100644 --- a/build.mk +++ b/build.mk @@ -87,7 +87,6 @@ TESTS= \ test/test-getsockname.o \ test/test-hrtime.o \ test/test-idle.o \ - test/test-ip6-addr.o \ test/test-ipc.o \ test/test-ipc-send-recv.o \ test/test-loop-handles.o \ diff --git a/checksparse.sh b/checksparse.sh index a75039fc..01fac07a 100755 --- a/checksparse.sh +++ b/checksparse.sh @@ -107,7 +107,6 @@ test/test-getaddrinfo.c test/test-getsockname.c test/test-hrtime.c test/test-idle.c -test/test-ip6-addr.c test/test-ipc-send-recv.c test/test-ipc.c test/test-loop-handles.c diff --git a/src/inet.c b/src/inet.c index d8848988..8f9d89b0 100644 --- a/src/inet.c +++ b/src/inet.c @@ -229,7 +229,7 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) { curtok = src; seen_xdigits = 0; val = 0; - while ((ch = *src++) != '\0' && ch != '%') { + while ((ch = *src++) != '\0') { const char *pch; if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) @@ -260,18 +260,7 @@ static uv_err_t inet_pton6(const char *src, unsigned char *dst) { continue; } if (ch == '.' && ((tp + sizeof(struct in_addr)) <= endp)) { - uv_err_t err; - - /* Scope id present, parse ipv4 addr without it */ - pch = strchr(curtok, '%'); - if (pch != NULL) { - char tmp[sizeof "255.255.255.255"]; - - memcpy(tmp, curtok, pch - curtok); - curtok = tmp; - src = pch; - } - err = inet_pton4(curtok, tp); + uv_err_t err = inet_pton4(curtok, tp); if (err.code == 0) { tp += sizeof(struct in_addr); seen_xdigits = 0; diff --git a/test/test-ip6-addr.c b/test/test-ip6-addr.c deleted file mode 100644 index 3b4cb8fe..00000000 --- a/test/test-ip6-addr.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include "uv.h" -#include "task.h" - -#define GOOD_ADDR_LIST(X) \ - X("::") \ - X("::1") \ - X("fe80::1") \ - X("fe80::") \ - X("fe80::2acf:daff:fedd:342a") \ - X("fe80:0:0:0:2acf:daff:fedd:342a") \ - X("fe80:0:0:0:2acf:daff:1.2.3.4") \ - -#define BAD_ADDR_LIST(X) \ - X(":::1") \ - X("abcde::1") \ - X("fe80:0:0:0:2acf:daff:fedd:342a:5678") \ - X("fe80:0:0:0:2acf:daff:abcd:1.2.3.4") \ - X("fe80:0:0:2acf:daff:1.2.3.4.5") \ - -#define TEST_GOOD(ADDR) \ - ASSERT(uv_inet_pton(AF_INET6, ADDR, &addr).code == UV_OK); \ - ASSERT(uv_inet_pton(AF_INET6, ADDR "%en1", &addr).code == UV_OK); \ - ASSERT(uv_inet_pton(AF_INET6, ADDR "%%%%", &addr).code == UV_OK); \ - ASSERT(uv_inet_pton(AF_INET6, ADDR "%en1:1.2.3.4", &addr).code == UV_OK); \ - -#define TEST_BAD(ADDR) \ - ASSERT(uv_inet_pton(AF_INET6, ADDR, &addr).code != UV_OK); \ - ASSERT(uv_inet_pton(AF_INET6, ADDR "%en1", &addr).code != UV_OK); \ - ASSERT(uv_inet_pton(AF_INET6, ADDR "%%%%", &addr).code != UV_OK); \ - ASSERT(uv_inet_pton(AF_INET6, ADDR "%en1:1.2.3.4", &addr).code != UV_OK); \ - -TEST_IMPL(ip6_pton) { - struct in6_addr addr; - - GOOD_ADDR_LIST(TEST_GOOD) - BAD_ADDR_LIST(TEST_BAD) - - MAKE_VALGRIND_HAPPY(); - return 0; -} - -#undef GOOD_ADDR_LIST -#undef BAD_ADDR_LIST diff --git a/test/test-list.h b/test/test-list.h index 739de09b..c280ca95 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -37,7 +37,6 @@ TEST_DECLARE (semaphore_2) TEST_DECLARE (semaphore_3) TEST_DECLARE (tty) TEST_DECLARE (stdio_over_pipes) -TEST_DECLARE (ip6_pton) TEST_DECLARE (ipc_listen_before_write) TEST_DECLARE (ipc_listen_after_write) #ifndef _WIN32 @@ -266,7 +265,6 @@ TASK_LIST_START TEST_ENTRY (pipe_server_close) TEST_ENTRY (tty) TEST_ENTRY (stdio_over_pipes) - TEST_ENTRY (ip6_pton) TEST_ENTRY (ipc_listen_before_write) TEST_ENTRY (ipc_listen_after_write) #ifndef _WIN32 diff --git a/uv.gyp b/uv.gyp index 04c8e2da..4e87dc1a 100644 --- a/uv.gyp +++ b/uv.gyp @@ -305,7 +305,6 @@ 'test/test-getsockname.c', 'test/test-hrtime.c', 'test/test-idle.c', - 'test/test-ip6-addr.c', 'test/test-ipc.c', 'test/test-ipc-send-recv.c', 'test/test-list.h', From ffb49220cf83d251fb7681a28992dc29fdadc9c7 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Mon, 14 Apr 2014 13:42:14 +0400 Subject: [PATCH 4/4] win: always leave crit section in get_proc_title fix #1235 --- src/win/util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win/util.c b/src/win/util.c index 898dcb49..6e6f6201 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -425,6 +425,7 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) { * we must query it with getConsoleTitleW */ if (!process_title && uv__get_process_title() == -1) { + LeaveCriticalSection(&process_title_lock); return uv__new_sys_error(GetLastError()); }