aboutsummaryrefslogtreecommitdiffstats
path: root/tools/gpg-connect-agent.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2023-07-03 01:20:06 +0000
committerNIIBE Yutaka <[email protected]>2023-07-03 01:20:06 +0000
commita0ff2919f710a7d5b55ac1cc9106de71229b7c56 (patch)
tree264d2a9eab4f9d5fada49a5d42d7fa822cb4f7e3 /tools/gpg-connect-agent.c
parentcommon:iobuf: Avoid losing bits of HANDLE on Windows 64-bit. (diff)
downloadgnupg-a0ff2919f710a7d5b55ac1cc9106de71229b7c56.tar.gz
gnupg-a0ff2919f710a7d5b55ac1cc9106de71229b7c56.zip
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 <[email protected]>
Diffstat (limited to 'tools/gpg-connect-agent.c')
-rw-r--r--tools/gpg-connect-agent.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c
index 4dfb57896..6be401c4f 100644
--- a/tools/gpg-connect-agent.c
+++ b/tools/gpg-connect-agent.c
@@ -1038,6 +1038,7 @@ do_open (char *line)
#if defined(HAVE_W32_SYSTEM)
{
HANDLE prochandle, handle, newhandle;
+ char numbuf[35];
handle = (void*)_get_osfhandle (fd);
@@ -1060,11 +1061,13 @@ do_open (char *line)
}
CloseHandle (prochandle);
open_fd_table[fd].handle = newhandle;
+
+ snprintf (numbuf, sizeof numbuf, "%p", open_fd_table[fd].handle);
+ set_var (varname, numbuf);
}
if (opt.verbose)
log_info ("file '%s' opened in \"%s\" mode, fd=%p (libc=%d)\n",
name, mode, open_fd_table[fd].handle, fd);
- set_int_var (varname, (int)open_fd_table[fd].handle);
#else /* Unix */
if (opt.verbose)
log_info ("file '%s' opened in \"%s\" mode, fd=%d\n",
@@ -1085,13 +1088,28 @@ do_open (char *line)
static void
do_close (char *line)
{
- int fd = atoi (line);
+ int fd;
#ifdef HAVE_W32_SYSTEM
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++)
- 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;
if (i < DIM (open_fd_table))
fd = i;
@@ -1100,6 +1118,8 @@ do_close (char *line)
log_error ("given fd (system handle) has not been opened\n");
return;
}
+#else
+ fd = atoi (line);
#endif
if (fd < 0 || fd >= DIM (open_fd_table))
@@ -1130,7 +1150,7 @@ do_showopen (void)
if (open_fd_table[i].inuse)
{
#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
printf ("%-15d\n", i);
#endif