From 18081e2ecf43de2be6ad5a7ca3384e1e2b66914d Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 23 Oct 2024 10:40:36 +0200 Subject: gpgsm: Terminate key listing on output write error. * sm/keylist.c (list_internal_keys): Detect write errors to the output stream. * sm/server.c (any_failure_printed): New var. (gpgsm_status2): Handle new var. Move statusfp init to ... (gpgsm_init_statusfp): new function. (gpgsm_exit_failure_status): New. * sm/gpgsm.c (main): Explicit statusfp init. (gpgsm_exit): Print failure status on error. -- Test by using gpgsm -k >/dev/full gpgsm -k --wit-colons >/dev/full and also by redirecting to a file on a small partition. GnuPG-bug-id: 6185 --- sm/gpgsm.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sm/gpgsm.c') diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 26b05773c..bea0184e3 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -1803,6 +1803,10 @@ main ( int argc, char **argv) gnupg_inhibit_set_foregound_window (1); } + /* Better make sure that we have a statusfp so that a failure status + * in gpgsm_exit can work even w/o any preeding status messages. */ + gpgsm_init_statusfp (&ctrl); + /* Add default keybox. */ if (!nrings && default_keyring && !opt.use_keyboxd) { @@ -2356,6 +2360,12 @@ gpgsm_exit (int rc) else if (opt.assert_signer_list && !assert_signer_true) rc = 1; + /* If we had an error but not printed an error message, do it now. + * Note that the function will never print a second failure status + * line. */ + if (rc) + gpgsm_exit_failure_status (); + gcry_control (GCRYCTL_UPDATE_RANDOM_SEED_FILE); if (opt.debug & DBG_MEMSTAT_VALUE) { -- cgit v1.2.3