Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
52762d9d by Krish Ganatra at 2026-02-07T17:20:19+00:00
win32: process: fix spawn failure when stderr is not associated with a stream

Previously, vlc_process_Spawn unconditionally passed STDERR_FILENO (2)
to the spawner.

The code was missing validation for this descriptor. As a result, it
passed an invalid handle when stderr was not associated with a stream,
which caused process creation to fail.

This failure was observed in the logs as:
> main libvlc error: Fail to create Process in process_pool

To safely pass a file descriptor, we must use _get_osfhandle to
validate that it points to a real handle. On Windows, this function
returns the special value -2 (indicating no associated stream). This
patch adds the missing check ensuring we only pass STDERR_FILENO if
the underlying handle is valid (neither -1 nor -2).

- - - - -


1 changed file:

- src/win32/process.c


Changes:

=====================================
src/win32/process.c
=====================================
@@ -12,6 +12,7 @@
 #endif
 
 #include <windows.h>
+#include <io.h>
 
 #include <vlc_common.h>
 #include <vlc_process.h>
@@ -122,8 +123,14 @@ vlc_process_Spawn(const char *path, int argc, const char 
*const *argv)
         errno = EINVAL;
         goto end;
     }
+    
+    int stderr_fd = -1;
+    intptr_t h_err = _get_osfhandle(STDERR_FILENO);
+    if (h_err != -1 && h_err != -2) {
+        stderr_fd = STDERR_FILENO;
+    }
 
-    int process_fds[4] = {extfd_in, extfd_out, STDERR_FILENO, -1};
+    int process_fds[4] = {extfd_in, extfd_out, stderr_fd, -1};
 
     /* `argc + 2`, 1 for the process->path and the last to be NULL */
     args = malloc((argc + 2) * sizeof(*args));



View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/52762d9d070b83272f442424534881b7b93db695

-- 
View it on GitLab: 
https://code.videolan.org/videolan/vlc/-/commit/52762d9d070b83272f442424534881b7b93db695
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to