[packages/libuv] Rel 3. Fix handle queue corruption after a failed uv_spawn()
arekm
arekm at pld-linux.org
Thu Oct 29 08:43:51 CET 2026
commit bac098f78747e40c6c8b9517d1e32bf0aa9afa5a
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Oct 29 02:01:22 2026 +0100
Rel 3. Fix handle queue corruption after a failed uv_spawn()
libuv-idna-continuation-bytes.patch | 157 ++++++++++++++++++++++++++++++++++
libuv-spawn-queue-double-remove.patch | 109 +++++++++++++++++++++++
libuv.spec | 10 ++-
3 files changed, 274 insertions(+), 2 deletions(-)
---
diff --git a/libuv.spec b/libuv.spec
index c758181..52e0401 100644
--- a/libuv.spec
+++ b/libuv.spec
@@ -7,13 +7,17 @@ Summary: Multi-platform support library with a focus on asynchronous I/O
Summary(pl.UTF-8): Wieloplatformowa biblioteka wspierająca skupiająca się na asynchronicznym we/wy
Name: libuv
Version: 1.53.0
-Release: 2
+Release: 3
# the licensing breakdown is described in detail in the LICENSE file
License: MIT and BSD and ISC
Group: Libraries
Source0: https://dist.libuv.org/dist/v%{version}/%{name}-v%{version}.tar.gz
# Source0-md5: c4099213c7751373bb58fc6851cb21c7
-URL: http://libuv.org/
+# https://github.com/libuv/libuv/commit/eeaf0a36
+Patch0: %{name}-spawn-queue-double-remove.patch
+# https://github.com/libuv/libuv/commit/ec192883
+Patch1: %{name}-idna-continuation-bytes.patch
+URL: https://libuv.org/
BuildRequires: autoconf >= 2.57
BuildRequires: automake >= 1:1.12
BuildRequires: libtool >= 2:2
@@ -57,6 +61,8 @@ Statyczna biblioteka libuv.
%prep
%setup -q -n %{name}-v%{version}
+%patch -P0 -p1
+%patch -P1 -p1
# serial-tests is available in v1.12 and newer.
echo "m4_define([UV_EXTRA_AUTOMAKE_FLAGS], [serial-tests])" > m4/libuv-extra-automake-flags.m4
diff --git a/libuv-idna-continuation-bytes.patch b/libuv-idna-continuation-bytes.patch
new file mode 100644
index 0000000..fbdc64a
--- /dev/null
+++ b/libuv-idna-continuation-bytes.patch
@@ -0,0 +1,157 @@
+From ec1928832534e18b2941d0ec629623a3e390cec4 Mon Sep 17 00:00:00 2001
+From: fhgffy <102001626+fhgffy at users.noreply.github.com>
+Date: Sat, 10 Oct 2026 05:41:27 +0800
+Subject: [PATCH] idna: reject invalid continuation bytes (#5326)
+
+The continuation-byte check combines high bits with XOR, allowing
+invalid bytes to cancel each other out. E2 41 42 is decoded as U+2042
+and successfully converted to IDNA instead of being rejected.
+
+Validate each continuation byte before decoding the code point while
+preserving valid-input behavior and cursor advancement on errors.
+
+Add decoder, IDNA and synchronous/asynchronous getaddrinfo regressions.
+---
+ src/idna.c | 4 +++-
+ test/test-getaddrinfo.c | 38 ++++++++++++++++++++++++++++++++++++++
+ test/test-idna.c | 26 ++++++++++++++++++++++++++
+ test/test-list.h | 2 ++
+ 4 files changed, 69 insertions(+), 1 deletion(-)
+
+diff --git a/src/idna.c b/src/idna.c
+index db1edafbec3..5096d0ef03d 100644
+--- a/src/idna.c
++++ b/src/idna.c
+@@ -114,7 +114,9 @@ static unsigned uv__utf8_decode1_slow(const char** p,
+ return -1; /* Invalid continuation byte. */
+ }
+
+- if (0x80 != (0xC0 & (b ^ c ^ d)))
++ if ((b & 0xC0) != 0x80 ||
++ (c & 0xC0) != 0x80 ||
++ (d & 0xC0) != 0x80)
+ return -1; /* Invalid sequence. */
+
+ b &= 63;
+diff --git a/test/test-getaddrinfo.c b/test/test-getaddrinfo.c
+index 3f81a9230f5..a29e987ea69 100644
+--- a/test/test-getaddrinfo.c
++++ b/test/test-getaddrinfo.c
+@@ -132,6 +132,44 @@ TEST_IMPL(getaddrinfo_fail_sync) {
+ }
+
+
++TEST_IMPL(getaddrinfo_invalid_utf8) {
++#ifdef __MVS__
++ RETURN_SKIP("IDNA conversion is not supported on z/OS.");
++#else
++ static const char* names[] = {
++ "\xE2\x41\x42",
++ "\xF1\x41\x42\x80"
++ };
++ struct addrinfo hints;
++ uv_getaddrinfo_t req;
++ size_t i;
++
++ memset(&hints, 0, sizeof(hints));
++ hints.ai_flags = AI_NUMERICHOST;
++
++ for (i = 0; i < ARRAY_SIZE(names); i++) {
++ ASSERT_EQ(UV_EINVAL, uv_getaddrinfo(NULL,
++ &req,
++ NULL,
++ names[i],
++ NULL,
++ &hints));
++ ASSERT_EQ(UV_EINVAL, uv_getaddrinfo(uv_default_loop(),
++ &req,
++ getaddrinfo_fail_cb,
++ names[i],
++ NULL,
++ &hints));
++ }
++
++ ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_DEFAULT));
++ ASSERT_OK(fail_cb_called);
++ MAKE_VALGRIND_HAPPY(uv_default_loop());
++ return 0;
++#endif
++}
++
++
+ TEST_IMPL(getaddrinfo_basic) {
+ /* TODO(gengjiawen): Fix test on QEMU. */
+ #if defined(__QEMU__)
+diff --git a/test/test-idna.c b/test/test-idna.c
+index ed8fad813a0..87cf50c997c 100644
+--- a/test/test-idna.c
++++ b/test/test-idna.c
+@@ -33,8 +33,20 @@
+ #include <string.h>
+
+ TEST_IMPL(utf8_decode1) {
++ static const char invalid[][5] = {
++ "\xE2\x41\x42",
++ "\xE2\xC1\xC2",
++ "\xF1\x41\x42\x80",
++ "\xF1\x41\x80\x42",
++ "\xF1\x80\x41\x42",
++ "\xF1\xC1\xC2\x80",
++ "\xF1\xC1\x80\xC2",
++ "\xF1\x80\xC1\xC2",
++ "\xF1\x01\x41\xC1"
++ };
+ const char* p;
+ char b[32];
++ size_t j;
+ int i;
+
+ /* ASCII. */
+@@ -102,6 +114,14 @@ TEST_IMPL(utf8_decode1) {
+ ASSERT_PTR_EQ(p, b + i);
+ }
+
++ /* Invalid continuation bytes must not cancel each other out. */
++ for (j = 0; j < ARRAY_SIZE(invalid); j++) {
++ p = invalid[j];
++ ASSERT_EQ((unsigned) -1,
++ uv__utf8_decode1(&p, invalid[j] + strlen(invalid[j])));
++ ASSERT_PTR_EQ(p, invalid[j] + strlen(invalid[j]));
++ }
++
+ return 0;
+ }
+
+@@ -160,6 +180,12 @@ TEST_IMPL(idna_toascii) {
+ F("\xC0\x80\xC1\x80", UV_EINVAL); /* Overlong UTF-8 sequence. */
+ F("\xC0\x80\xC1\x80.com", UV_EINVAL); /* Overlong UTF-8 sequence. */
+ F("", UV_EINVAL);
++ F("\xE2\x41\x42", UV_EINVAL);
++ F("\xE2\xC1\xC2.com", UV_EINVAL);
++ F("\xF1\x41\x42\x80", UV_EINVAL);
++ F("\xF1\x41\x80\x42.com", UV_EINVAL);
++ F("\xF1\x80\x41\x42", UV_EINVAL);
++ F("\xF1\x01\x41\xC1.com", UV_EINVAL);
+ /* No conversion. */
+ T(".", ".");
+ T(".com", ".com");
+diff --git a/test/test-list.h b/test/test-list.h
+index 6b50e77f8e5..2c7cb499521 100644
+--- a/test/test-list.h
++++ b/test/test-list.h
+@@ -331,6 +331,7 @@ TEST_DECLARE (hrtime)
+ TEST_DECLARE (clock_gettime)
+ TEST_DECLARE (getaddrinfo_fail)
+ TEST_DECLARE (getaddrinfo_fail_sync)
++TEST_DECLARE (getaddrinfo_invalid_utf8)
+ TEST_DECLARE (getaddrinfo_basic)
+ TEST_DECLARE (getaddrinfo_basic_sync)
+ TEST_DECLARE (getaddrinfo_concurrent)
+@@ -1045,6 +1046,7 @@ TASK_LIST_START
+
+ TEST_ENTRY_CUSTOM (getaddrinfo_fail, 0, 0, 10000)
+ TEST_ENTRY_CUSTOM (getaddrinfo_fail_sync, 0, 0, 10000)
++ TEST_ENTRY (getaddrinfo_invalid_utf8)
+
+ TEST_ENTRY (getaddrinfo_basic)
+ TEST_ENTRY (getaddrinfo_basic_sync)
diff --git a/libuv-spawn-queue-double-remove.patch b/libuv-spawn-queue-double-remove.patch
new file mode 100644
index 0000000..17f109f
--- /dev/null
+++ b/libuv-spawn-queue-double-remove.patch
@@ -0,0 +1,109 @@
+From eeaf0a368ff9149f6d27973e5c1e4e7e0fd79383 Mon Sep 17 00:00:00 2001
+From: Takeshi Sone <takeshi.sone at gmail.com>
+Date: Sat, 24 Oct 2026 04:10:39 +0900
+Subject: [PATCH] unix: don't remove process handle from queue twice (#5352)
+
+uv_spawn() removed the handle from loop->handle_queue on error and
+uv_close() removed it again. uv__queue_remove() doesn't reset the
+handle's links, so the second call clobbers whatever they point to.
+
+uv_close() must be called after a failed uv_spawn() anyway, so leave
+the handle in the queue and let uv_close() remove it.
+
+Refs: https://github.com/libuv/libuv/pull/4980
+---
+ src/unix/process.c | 1 -
+ test/test-list.h | 2 ++
+ test/test-spawn.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 49 insertions(+), 1 deletion(-)
+
+diff --git a/src/unix/process.c b/src/unix/process.c
+index fd5bb208dab..a1406202dfa 100644
+--- a/src/unix/process.c
++++ b/src/unix/process.c
+@@ -1242,7 +1242,6 @@ int uv_spawn(uv_loop_t* loop,
+ return exec_errorno;
+
+ error:
+- uv__queue_remove(&process->handle_queue);
+ if (pipes != NULL) {
+ for (i = 0; i < stdio_count; i++) {
+ if (i < options->stdio_count)
+diff --git a/test/test-list.h b/test/test-list.h
+index 10578d373b3..de6253e75e3 100644
+--- a/test/test-list.h
++++ b/test/test-list.h
+@@ -350,6 +350,7 @@ TEST_DECLARE (socket_buffer_size)
+ TEST_DECLARE (spawn_fails)
+ #ifndef _WIN32
+ TEST_DECLARE (spawn_fails_check_for_waitpid_cleanup)
++TEST_DECLARE (spawn_fails_stdio_close)
+ #endif
+ TEST_DECLARE (spawn_empty_env)
+ TEST_DECLARE (spawn_exit_code)
+@@ -1088,6 +1089,7 @@ TASK_LIST_START
+ TEST_ENTRY (spawn_fails)
+ #ifndef _WIN32
+ TEST_ENTRY (spawn_fails_check_for_waitpid_cleanup)
++ TEST_ENTRY (spawn_fails_stdio_close)
+ #endif
+ TEST_ENTRY (spawn_empty_env)
+ TEST_ENTRY (spawn_exit_code)
+diff --git a/test/test-spawn.c b/test/test-spawn.c
+index 0816f8bbd65..ef499e5c660 100644
+--- a/test/test-spawn.c
++++ b/test/test-spawn.c
+@@ -229,6 +229,53 @@ TEST_IMPL(spawn_fails_check_for_waitpid_cleanup) {
+ MAKE_VALGRIND_HAPPY(uv_default_loop());
+ return 0;
+ }
++
++
++static void count_handle_cb(uv_handle_t* handle, void* arg) {
++ (*(int*) arg)++;
++}
++
++
++/* A spawn that fails while it sets up the child's stdio leaves the process
++ * handle in the loop's handle queue, so that uv_close(), which is required
++ * after a failed spawn too, takes it off exactly once, also with handles
++ * initialized before and after it. */
++TEST_IMPL(spawn_fails_stdio_close) {
++ uv_loop_t* loop;
++ uv_timer_t before;
++ uv_timer_t after;
++ uv_tcp_t not_a_pipe;
++ uv_stdio_container_t stdio[2];
++ int walked;
++
++ loop = uv_default_loop();
++ ASSERT_OK(uv_timer_init(loop, &before));
++ ASSERT_OK(uv_tcp_init(loop, ¬_a_pipe));
++
++ init_process_options("", fail_cb);
++ options.stdio = stdio;
++ options.stdio[0].flags = UV_IGNORE;
++ options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
++ options.stdio[1].data.stream = (uv_stream_t*) ¬_a_pipe;
++ options.stdio_count = 2;
++
++ ASSERT_EQ(UV_EINVAL, uv_spawn(loop, &process, &options));
++ uv_close((uv_handle_t*) &process, NULL);
++ ASSERT_OK(uv_timer_init(loop, &after));
++ uv_close((uv_handle_t*) ¬_a_pipe, NULL);
++ ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
++
++ walked = 0;
++ uv_walk(loop, count_handle_cb, &walked);
++ ASSERT_EQ(2, walked);
++
++ uv_close((uv_handle_t*) &before, NULL);
++ uv_close((uv_handle_t*) &after, NULL);
++ ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
++
++ MAKE_VALGRIND_HAPPY(loop);
++ return 0;
++}
+ #endif
+
+
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/libuv.git/commitdiff/bac098f78747e40c6c8b9517d1e32bf0aa9afa5a
More information about the pld-cvs-commit
mailing list