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

agent: Fix a race condition which results accessing finished scd.

* agent/call-daemon.c (daemon_start): Decision of connection/reuse of
CTX and assignment to ->ctx should be done with the lock.

--

When scdaemon is exiting and agent tries to spawn/connect/reconnect,
there is a race condition between detecting finish of scd and
spawn/connect/reconnect.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2024-06-11 15:21:19 +09:00
parent fee890a2ab
commit 563bfbb0be
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054

View File

@ -469,13 +469,12 @@ daemon_start (enum daemon_type type, ctrl_t ctrl)
} }
leave: leave:
rc = npth_mutex_unlock (&start_daemon_lock);
if (rc)
log_error ("failed to release the start_daemon lock: %s\n", strerror (rc));
xfree (abs_homedir); xfree (abs_homedir);
if (err) if (err)
{ {
rc = npth_mutex_unlock (&start_daemon_lock);
if (rc)
log_error ("failed to release the start_daemon lock: %s\n", strerror (rc));
daemon_unlock (type, ctrl, err); daemon_unlock (type, ctrl, err);
if (ctx) if (ctx)
assuan_release (ctx); assuan_release (ctx);
@ -484,6 +483,9 @@ daemon_start (enum daemon_type type, ctrl_t ctrl)
{ {
ctrl->d_local[type]->ctx = ctx; ctrl->d_local[type]->ctx = ctx;
ctrl->d_local[type]->invalid = 0; ctrl->d_local[type]->invalid = 0;
rc = npth_mutex_unlock (&start_daemon_lock);
if (rc)
log_error ("failed to release the start_daemon lock: %s\n", strerror (rc));
} }
return err; return err;
} }