1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

kbx: Fix a race condition which results no status report.

* kbx/keyboxd.h (kbxd_status_printf): New.
* kbx/backend-support.c (be_return_pubkey): Use kbxd_status_printf.
* kbx/kbxserver.c (kbxd_status_printf): New.
* kbxd_start_command_handler (kbxd_start_command_handler): Don't
use set_assuan_context_func, because the function pointer is
shared by multiple threads.

--

GnuPG-bug-id: 5948
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2022-04-27 13:49:30 +09:00
parent 35b1755070
commit bd5dbdb813
3 changed files with 25 additions and 11 deletions

View File

@ -173,18 +173,18 @@ be_return_pubkey (ctrl_t ctrl, const void *buffer, size_t buflen,
char hexubid[2*UBID_LEN+1]; char hexubid[2*UBID_LEN+1];
bin2hex (ubid, UBID_LEN, hexubid); bin2hex (ubid, UBID_LEN, hexubid);
err = status_printf (ctrl, "PUBKEY_INFO", "%d %s %c%c %d %d", err = kbxd_status_printf (ctrl, "PUBKEY_INFO", "%d %s %c%c %d %d",
pubkey_type, hexubid, pubkey_type, hexubid,
is_ephemeral? 'e':'-', is_ephemeral? 'e':'-',
is_revoked? 'r':'-', is_revoked? 'r':'-',
uid_no, pk_no); uid_no, pk_no);
if (err) if (err)
goto leave; goto leave;
if (ctrl->no_data_return) if (ctrl->no_data_return)
err = 0; err = 0;
else else
err = kbxd_write_data_line(ctrl, buffer, buflen); err = kbxd_write_data_line (ctrl, buffer, buflen);
leave: leave:
return err; return err;

View File

@ -173,6 +173,23 @@ kbxd_writen (estream_t fp, const void *buffer, size_t length)
return err; return err;
} }
/* This status functions expects a printf style format string. */
gpg_error_t
kbxd_status_printf (ctrl_t ctrl, const char *keyword, const char *format, ...)
{
gpg_error_t err;
va_list arg_ptr;
assuan_context_t ctx = get_assuan_ctx_from_ctrl (ctrl);
if (!ctx) /* Oops - no assuan context. */
return gpg_error (GPG_ERR_NOT_PROCESSED);
va_start (arg_ptr, format);
err = vprint_assuan_status (ctx, keyword, format, arg_ptr);
va_end (arg_ptr);
return err;
}
/* A wrapper around assuan_send_data which makes debugging the output /* A wrapper around assuan_send_data which makes debugging the output
* in verbose mode easier. It also takes CTRL as argument. */ * in verbose mode easier. It also takes CTRL as argument. */
@ -975,10 +992,6 @@ kbxd_start_command_handler (ctrl_t ctrl, gnupg_fd_t fd, unsigned int session_id)
ctrl->server_local->next_session = session_list; ctrl->server_local->next_session = session_list;
session_list = ctrl->server_local; session_list = ctrl->server_local;
/* The next call enable the use of status_printf. */
set_assuan_context_func (get_assuan_ctx_from_ctrl);
for (;;) for (;;)
{ {
rc = assuan_accept (ctx); rc = assuan_accept (ctx);
@ -1029,7 +1042,6 @@ kbxd_start_command_handler (ctrl_t ctrl, gnupg_fd_t fd, unsigned int session_id)
assuan_close_output_fd (ctx); assuan_close_output_fd (ctx);
set_assuan_context_func (NULL);
ctrl->server_local->assuan_ctx = NULL; ctrl->server_local->assuan_ctx = NULL;
assuan_release (ctx); assuan_release (ctx);

View File

@ -171,6 +171,8 @@ void kbxd_sighup_action (void);
/*-- kbxserver.c --*/ /*-- kbxserver.c --*/
gpg_error_t kbxd_status_printf (ctrl_t ctrl, const char *keyword,
const char *format, ...);
gpg_error_t kbxd_write_data_line (ctrl_t ctrl, gpg_error_t kbxd_write_data_line (ctrl_t ctrl,
const void *buffer_arg, size_t size); const void *buffer_arg, size_t size);
void kbxd_start_command_handler (ctrl_t, gnupg_fd_t, unsigned int); void kbxd_start_command_handler (ctrl_t, gnupg_fd_t, unsigned int);