From 417e8588f3ef3927e073ffa9ac251b3e3dd6a545 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 19 Jan 2023 16:13:35 +0100 Subject: [PATCH] gpgtar: Make --status-fd option for fds > 2 work * tools/gpgtar-create.c (gpgtar_create): Do not close the status_fd in spawn. * tools/gpgtar-extract.c (gpgtar_extract): Ditto. * tools/gpgtar-list.c (gpgtar_list): Ditto. -- Note that this fix does not handle file descripotors passed via the --gpg-args options. GnuPG-bug-id: 6348 --- tools/gpgtar-create.c | 6 +++++- tools/gpgtar-extract.c | 6 +++++- tools/gpgtar-list.c | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/gpgtar-create.c b/tools/gpgtar-create.c index e642da0b9..10906584c 100644 --- a/tools/gpgtar-create.c +++ b/tools/gpgtar-create.c @@ -1151,6 +1151,7 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, { strlist_t arg; ccparray_t ccp; + int except[2] = { -1, -1 }; const char **argv; /* '--encrypt' may be combined with '--symmetric', but 'encrypt' @@ -1174,6 +1175,7 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%d", opt.status_fd); ccparray_put (&ccp, tmpbuf); + except[0] = opt.status_fd; } ccparray_put (&ccp, "--output"); @@ -1205,7 +1207,9 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, goto leave; } - err = gnupg_spawn_process (opt.gpg_program, argv, NULL, NULL, + err = gnupg_spawn_process (opt.gpg_program, argv, + except[0] == -1? NULL : except, + NULL, (GNUPG_SPAWN_KEEP_STDOUT | GNUPG_SPAWN_KEEP_STDERR), &outstream, NULL, NULL, &pid); diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c index 832039b2c..0112282d3 100644 --- a/tools/gpgtar-extract.c +++ b/tools/gpgtar-extract.c @@ -369,6 +369,7 @@ gpgtar_extract (const char *filename, int decrypt) { strlist_t arg; ccparray_t ccp; + int except[2] = { -1, -1 }; const char **argv; ccparray_init (&ccp, 0); @@ -382,6 +383,7 @@ gpgtar_extract (const char *filename, int decrypt) snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%d", opt.status_fd); ccparray_put (&ccp, tmpbuf); + except[0] = opt.status_fd; } if (opt.with_log) { @@ -408,7 +410,9 @@ gpgtar_extract (const char *filename, int decrypt) goto leave; } - err = gnupg_spawn_process (opt.gpg_program, argv, NULL, NULL, + err = gnupg_spawn_process (opt.gpg_program, argv, + except[0] == -1? NULL : except, + NULL, ((filename? 0 : GNUPG_SPAWN_KEEP_STDIN) | GNUPG_SPAWN_KEEP_STDERR), NULL, &stream, NULL, &pid); diff --git a/tools/gpgtar-list.c b/tools/gpgtar-list.c index 08ab9672e..37951d684 100644 --- a/tools/gpgtar-list.c +++ b/tools/gpgtar-list.c @@ -468,6 +468,7 @@ gpgtar_list (const char *filename, int decrypt) { strlist_t arg; ccparray_t ccp; + int except[2] = { -1, -1 }; const char **argv; ccparray_init (&ccp, 0); @@ -481,6 +482,7 @@ gpgtar_list (const char *filename, int decrypt) snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%d", opt.status_fd); ccparray_put (&ccp, tmpbuf); + except[0] = opt.status_fd; } ccparray_put (&ccp, "--output"); ccparray_put (&ccp, "-"); @@ -501,7 +503,9 @@ gpgtar_list (const char *filename, int decrypt) goto leave; } - err = gnupg_spawn_process (opt.gpg_program, argv, NULL, NULL, + err = gnupg_spawn_process (opt.gpg_program, argv, + except[0] == -1? NULL : except, + NULL, ((filename? 0 : GNUPG_SPAWN_KEEP_STDIN) | GNUPG_SPAWN_KEEP_STDERR), NULL, &stream, NULL, &pid);