1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-05-28 21:50:02 +02:00

tools:gpg-connect-agent: Fix use of HANDLE on Windows.

* tools/gpg-connect-agent.c [HAVE_W32_SYSTEM] (do_open): Use %p to
format the HANDLE.
[HAVE_W32_SYSTEM] (do_close): Use gnupg_parse_fdstr to parse the
string representation of the HANDLE.  Use %p.

--

GnuPG-bug-id: 6508
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2023-07-03 10:20:06 +09:00
parent 250fff0f6e
commit a0ff2919f7
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054

View File

@ -1038,6 +1038,7 @@ do_open (char *line)
#if defined(HAVE_W32_SYSTEM) #if defined(HAVE_W32_SYSTEM)
{ {
HANDLE prochandle, handle, newhandle; HANDLE prochandle, handle, newhandle;
char numbuf[35];
handle = (void*)_get_osfhandle (fd); handle = (void*)_get_osfhandle (fd);
@ -1060,11 +1061,13 @@ do_open (char *line)
} }
CloseHandle (prochandle); CloseHandle (prochandle);
open_fd_table[fd].handle = newhandle; open_fd_table[fd].handle = newhandle;
snprintf (numbuf, sizeof numbuf, "%p", open_fd_table[fd].handle);
set_var (varname, numbuf);
} }
if (opt.verbose) if (opt.verbose)
log_info ("file '%s' opened in \"%s\" mode, fd=%p (libc=%d)\n", log_info ("file '%s' opened in \"%s\" mode, fd=%p (libc=%d)\n",
name, mode, open_fd_table[fd].handle, fd); name, mode, open_fd_table[fd].handle, fd);
set_int_var (varname, (int)open_fd_table[fd].handle);
#else /* Unix */ #else /* Unix */
if (opt.verbose) if (opt.verbose)
log_info ("file '%s' opened in \"%s\" mode, fd=%d\n", log_info ("file '%s' opened in \"%s\" mode, fd=%d\n",
@ -1085,13 +1088,28 @@ do_open (char *line)
static void static void
do_close (char *line) do_close (char *line)
{ {
int fd = atoi (line); int fd;
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
int i; int i;
gpg_error_t err;
es_syshd_t syshd;
err = gnupg_parse_fdstr (line, &syshd);
if (err)
{
log_error ("given fd (system handle) is not valid\n");
return;
}
if (syshd.type == ES_SYSHD_FD)
{
log_error ("given fd is stdin/out/err\n");
return;
}
for (i=0; i < DIM (open_fd_table); i++) for (i=0; i < DIM (open_fd_table); i++)
if ( open_fd_table[i].inuse && open_fd_table[i].handle == (void*)fd) if (open_fd_table[i].inuse && open_fd_table[i].handle == syshd.u.handle)
break; break;
if (i < DIM (open_fd_table)) if (i < DIM (open_fd_table))
fd = i; fd = i;
@ -1100,6 +1118,8 @@ do_close (char *line)
log_error ("given fd (system handle) has not been opened\n"); log_error ("given fd (system handle) has not been opened\n");
return; return;
} }
#else
fd = atoi (line);
#endif #endif
if (fd < 0 || fd >= DIM (open_fd_table)) if (fd < 0 || fd >= DIM (open_fd_table))
@ -1130,7 +1150,7 @@ do_showopen (void)
if (open_fd_table[i].inuse) if (open_fd_table[i].inuse)
{ {
#ifdef HAVE_W32_SYSTEM #ifdef HAVE_W32_SYSTEM
printf ("%-15d (libc=%d)\n", (int)open_fd_table[i].handle, i); printf ("%p (libc=%d)\n", open_fd_table[i].handle, i);
#else #else
printf ("%-15d\n", i); printf ("%-15d\n", i);
#endif #endif