fix(native): pin node-pty cfset*speed with legacy baud codes for glibc 2.42+ (#33803)

* fix(native): pin node-pty cfset*speed with legacy baud codes for glibc 2.42+

glibc 2.42 versioned cfsetispeed/cfsetospeed (GLIBC_2.42) to take literal
rates and redefined B38400 as 38400U, so node-pty built on 2.42+ fails the
Ubuntu 20.04 floor gate. Pin both to the compat version alongside the
existing openpty/forkpty/pthread_sigmask pins, and pass the legacy CBAUD
code (__B38400 on 2.42+ headers, B38400 otherwise): the compat setters
reject literal rates with EINVAL, which left every PTY at speed 0.

Fixes #19420. Supersedes #19421.

Co-authored-by: MK <mkjung.github@gmail.com>

* fix(native): fail the build if pinned cfset*speed would get a non-legacy baud code

A 2.42+ header set without __B38400 would otherwise silently pass 38400U to the
compat setters and open every terminal at B0.

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
Co-authored-by: MK <mkjung.github@gmail.com>
This commit is contained in:
OrcaWin
2026-10-26 00:29:36 -07:00
committed by GitHub
co-authored by OrcaWin MK
parent 761cddff38
commit fcf5e7b418
2 changed files with 37 additions and 12 deletions
+34 -9
View File
@@ -297,7 +297,7 @@ index 181ccabbbe9c4948a9725fb1db907a68e9de01fc..67f31facf85562b67adbfbd04ce28ddd
process.send!({ consoleProcessList });
process.exit(0);
diff --git a/src/unix/pty.cc b/src/unix/pty.cc
index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a52c690e0a 100644
index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..5e67653b45061e9a9cad4b2d461d563e7baac249 100644
--- a/src/unix/pty.cc
+++ b/src/unix/pty.cc
@@ -23,7 +23,9 @@
@@ -310,7 +310,7 @@ index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a5
#include <thread>
#include <sys/types.h>
@@ -47,6 +49,25 @@
@@ -47,6 +49,39 @@
#include <termios.h>
#endif
@@ -330,13 +330,27 @@ index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a5
+__asm__(".symver openpty,openpty@" ORCA_GLIBC_COMPAT_VERSION);
+__asm__(".symver forkpty,forkpty@" ORCA_GLIBC_COMPAT_VERSION);
+__asm__(".symver pthread_sigmask,pthread_sigmask@" ORCA_GLIBC_COMPAT_VERSION);
+/* glibc 2.42 versioned cfset*speed to take literal rates (B38400 == 38400U);
+ * the pinned compat versions accept only the legacy CBAUD code (named
+ * __B38400 in 2.42+ headers) and return EINVAL otherwise (#19420). */
+__asm__(".symver cfsetispeed,cfsetispeed@" ORCA_GLIBC_COMPAT_VERSION);
+__asm__(".symver cfsetospeed,cfsetospeed@" ORCA_GLIBC_COMPAT_VERSION);
+# ifdef __B38400
+# define ORCA_B38400 __B38400
+# else
+# define ORCA_B38400 B38400
+# endif
+static_assert(ORCA_B38400 == 0000017, "pinned cfset*speed take legacy CBAUD codes");
+# endif
+#endif
+#ifndef ORCA_B38400
+# define ORCA_B38400 B38400
+#endif
+
/* Some platforms name VWERASE and VDISCARD differently */
#if !defined(VWERASE) && defined(VWERSE)
#define VWERASE VWERSE
@@ -228,6 +249,9 @@ Napi::Value PtyGetProc(const Napi::CallbackInfo& info);
@@ -228,6 +263,9 @@ Napi::Value PtyGetProc(const Napi::CallbackInfo& info);
static int
pty_nonblock(int);
@@ -346,7 +360,7 @@ index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a5
#if defined(__APPLE__)
static char *
pty_getproc(int);
@@ -237,13 +261,23 @@ pty_getproc(int, char *);
@@ -237,13 +275,23 @@ pty_getproc(int, char *);
#endif
#if defined(__APPLE__) || defined(__OpenBSD__)
@@ -371,7 +385,18 @@ index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a5
#endif
struct DelBuf {
@@ -367,14 +401,18 @@ Napi::Value PtyFork(const Napi::CallbackInfo& info) {
@@ -345,8 +393,8 @@ Napi::Value PtyFork(const Napi::CallbackInfo& info) {
term->c_cc[VSTATUS] = 20;
#endif
- cfsetispeed(term, B38400);
- cfsetospeed(term, B38400);
+ cfsetispeed(term, ORCA_B38400);
+ cfsetospeed(term, ORCA_B38400);
// helperPath
std::string helper_path = info[9].As<Napi::String>();
@@ -367,14 +415,18 @@ Napi::Value PtyFork(const Napi::CallbackInfo& info) {
argv[i + 3] = strdup(arg.c_str());
}
@@ -394,7 +419,7 @@ index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a5
#else
int argc = argv_.Length();
int argl = argc + 2;
@@ -445,6 +483,9 @@ Napi::Value PtyFork(const Napi::CallbackInfo& info) {
@@ -445,6 +497,9 @@ Napi::Value PtyFork(const Napi::CallbackInfo& info) {
if (pty_nonblock(master) == -1) {
throw Napi::Error::New(napiEnv, "Could not set master fd to nonblocking.");
}
@@ -404,7 +429,7 @@ index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a5
}
#endif
@@ -586,6 +627,23 @@ pty_nonblock(int fd) {
@@ -586,6 +641,23 @@ pty_nonblock(int fd) {
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
@@ -428,7 +453,7 @@ index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a5
/**
* pty_getproc
* Taken from tmux.
@@ -684,15 +742,73 @@ pty_getproc(int fd, char *tty) {
@@ -684,15 +756,73 @@ pty_getproc(int fd, char *tty) {
#endif
#if defined(__APPLE__)
@@ -504,7 +529,7 @@ index 7b4b9e1f990fbf95b51528bb56dc9717f5b87532..2ae787c5bd4f3eba470584dc658a01a5
for (; count < 3; count++) {
low_fds[count] = posix_openpt(O_RDWR);
@@ -706,80 +822,118 @@ pty_posix_spawn(char** argv, char** env,
@@ -706,80 +836,118 @@ pty_posix_spawn(char** argv, char** env,
POSIX_SPAWN_SETSID;
*master = posix_openpt(O_RDWR);
if (*master == -1) {
+3 -3
View File
@@ -184,7 +184,7 @@ patchedDependencies:
i18next-cli@1.74.2: 2ee32eef742615cd133e1a6940f027deb3723a8430bb7953bba3a6769b0aac47
lint-staged@16.4.0: 7333b3837f80a7fbd045964db6d76ba4fc118e49134bdbabb00585b6b7b60673
monaco-editor@0.55.1: 53b71f7d8a7c00b76ffdb73ce83d18e31692f193f5fafa6a390e48f5b3fdd636
node-pty@1.1.0: d3e7df08a1b7c11400cf9db039ece2b7c8a8d0ce4e2f79d81d52c10a67dc0440
node-pty@1.1.0: afb111afc31f8b97431dafce9833a989d7dbd7d525228dade858d520bcb6ec76
oxlint-plugin-anti-slop@0.1.2: c10c871702365a0c2c59e9f1c5fb92df97cae5755d534c0a3d83c6368f6feafe
sprintf-js@1.1.3: 05316a8b01f155fe19a1e0cb4042c81d43d798a76755c407684e1199a18b1e08
vitest@5.0.5: e53d360918437da97f766d322f487aabfbe10d1450ed98543491573b4d500cd2
@@ -232,7 +232,7 @@ importers:
version: 3.3.1
node-pty:
specifier: ^1.1.0
version: 1.1.0(patch_hash=d3e7df08a1b7c11400cf9db039ece2b7c8a8d0ce4e2f79d81d52c10a67dc0440)
version: 1.1.0(patch_hash=afb111afc31f8b97431dafce9833a989d7dbd7d525228dade858d520bcb6ec76)
posthog-node:
specifier: ^5.52.5
version: 5.52.5
@@ -13707,7 +13707,7 @@ snapshots:
node-int64@0.4.0: {}
node-pty@1.1.0(patch_hash=d3e7df08a1b7c11400cf9db039ece2b7c8a8d0ce4e2f79d81d52c10a67dc0440):
node-pty@1.1.0(patch_hash=afb111afc31f8b97431dafce9833a989d7dbd7d525228dade858d520bcb6ec76):
dependencies:
node-addon-api: 7.1.1