[PATCH] Cygwin: spawn: Make ch_spwan_local be fully initialized
    Takashi Yano 
    takashi.yano@nifty.ne.jp
       
    Fri Aug 15 21:35:11 GMT 2025
    
    
  
The class child_info_spawn has two constructors: one without arguments
and one with two arguments. The former does not initialize any members.
Commit 1f836c5f7394 used the latter to ensure that the local ch_spawn
(i.e., ch_spawn_local) would be properly initialized. However, this was
insufficient - it initialized only the base child_info members, not the
fields specific to child_info_spawn. This led to the issue reported in
https://cygwin.com/pipermail/cygwin/2025-August/258660.html.
This patch updates the former constructor to properly initialize all
member variables and switches ch_spawn_local to use it.
Addresses: https://cygwin.com/pipermail/cygwin/2025-August/258660.html
Fixes: 1f836c5f7394 ("Cygwin: spawn: Make system() thread-safe")
Reported-by: Denis Excoffier <cygwin@Denis-Excoffier.org>
Reviewed-by:
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
---
 winsup/cygwin/local_includes/child_info.h | 4 +++-
 winsup/cygwin/spawn.cc                    | 2 +-
 winsup/cygwin/syscalls.cc                 | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/winsup/cygwin/local_includes/child_info.h b/winsup/cygwin/local_includes/child_info.h
index 2da62ffaa..e359d3645 100644
--- a/winsup/cygwin/local_includes/child_info.h
+++ b/winsup/cygwin/local_includes/child_info.h
@@ -148,7 +148,9 @@ public:
   char filler[4];
 
   void cleanup ();
-  child_info_spawn () {};
+  child_info_spawn () : child_info (sizeof *this, _CH_NADA, false),
+    hExeced (NULL), ev (NULL), sem (NULL), cygpid (0),
+    moreinfo (NULL), __stdin (0), __stdout (0) {};
   child_info_spawn (child_info_types, bool);
   void record_children ();
   void reattach_children ();
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 680f0fefd..6cd97ec17 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -950,7 +950,7 @@ spawnve (int mode, const char *path, const char *const *argv,
   if (!envp)
     envp = empty_env;
 
-  child_info_spawn ch_spawn_local (_CH_NADA, false);
+  child_info_spawn ch_spawn_local;
   switch (_P_MODE (mode))
     {
     case _P_OVERLAY:
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 863f8f23c..83a54ca05 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -4535,7 +4535,7 @@ popen (const char *command, const char *in_type)
       fcntl (stdchild, F_SETFD, stdchild_state | FD_CLOEXEC);
 
       /* Start a shell process to run the given command without forking. */
-      child_info_spawn ch_spawn_local (_CH_NADA, false);
+      child_info_spawn ch_spawn_local;
       pid_t pid = ch_spawn_local.worker ("/bin/sh", argv, environ, _P_NOWAIT,
 					 __std[0], __std[1]);
 
-- 
2.45.1
    
    
More information about the Cygwin-patches
mailing list