1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-12 22:11:29 +02:00

common:w32: Fix INEXTRA handling.

* common/exectool.c (gnupg_exec_tool_stream): On Windows, it's
HANDLE which a child process inherits.

--

GnuPG-bug-id: 7139
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2024-06-04 14:50:57 +09:00
parent ed118e2ed5
commit 8624482160
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054

View File

@ -329,7 +329,11 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
estream_t extrafp = NULL; estream_t extrafp = NULL;
estream_t outfp = NULL, errfp = NULL; estream_t outfp = NULL, errfp = NULL;
es_poll_t fds[4]; es_poll_t fds[4];
#ifdef HAVE_W32_SYSTEM
HANDLE exceptclose[2];
#else
int exceptclose[2]; int exceptclose[2];
#endif
int extrapipe[2] = {-1, -1}; int extrapipe[2] = {-1, -1};
char extrafdbuf[20]; char extrafdbuf[20];
const char *argsave = NULL; const char *argsave = NULL;
@ -339,6 +343,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
struct copy_buffer *cpbuf_in = NULL, *cpbuf_out = NULL, *cpbuf_extra = NULL; struct copy_buffer *cpbuf_in = NULL, *cpbuf_out = NULL, *cpbuf_extra = NULL;
int quiet = 0; int quiet = 0;
gnupg_spawn_actions_t act = NULL; gnupg_spawn_actions_t act = NULL;
int i = 0;
memset (fds, 0, sizeof fds); memset (fds, 0, sizeof fds);
memset (&fderrstate, 0, sizeof fderrstate); memset (&fderrstate, 0, sizeof fderrstate);
@ -392,16 +397,20 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
gpg_strerror (err)); gpg_strerror (err));
goto leave; goto leave;
} }
exceptclose[0] = extrapipe[0]; /* Do not close in child. */ /* Do not close in child. */
exceptclose[1] = -1; #ifdef HAVE_W32_SYSTEM
exceptclose[i] = (HANDLE)_get_osfhandle (extrapipe[0]);
#else
exceptclose[i] = extrapipe[0];
#endif
/* Now find the argument marker and replace by the pipe's fd. /* Now find the argument marker and replace by the pipe's fd.
Yeah, that is an ugly non-thread safe hack but it safes us to Yeah, that is an ugly non-thread safe hack but it safes us to
create a copy of the array. */ create a copy of the array. */
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
snprintf (extrafdbuf, sizeof extrafdbuf, "-&%lu", snprintf (extrafdbuf, sizeof extrafdbuf, "-&%lu",
(unsigned long)_get_osfhandle (extrapipe[0])); (unsigned long)exceptclose[i]);
#else #else
snprintf (extrafdbuf, sizeof extrafdbuf, "-&%d", extrapipe[0]); snprintf (extrafdbuf, sizeof extrafdbuf, "-&%d", exceptclose[i]);
#endif #endif
for (argsaveidx=0; argv[argsaveidx]; argsaveidx++) for (argsaveidx=0; argv[argsaveidx]; argsaveidx++)
if (!strcmp (argv[argsaveidx], "-&@INEXTRA@")) if (!strcmp (argv[argsaveidx], "-&@INEXTRA@"))
@ -410,9 +419,14 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
argv[argsaveidx] = extrafdbuf; argv[argsaveidx] = extrafdbuf;
break; break;
} }
i++;
} }
else
exceptclose[0] = -1; #ifdef HAVE_W32_SYSTEM
exceptclose[i] = INVALID_HANDLE_VALUE;
#else
exceptclose[i] = -1;
#endif
err = gnupg_spawn_actions_new (&act); err = gnupg_spawn_actions_new (&act);
if (err) if (err)