1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-10 21:38:50 +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>
(cherry picked from commit 563bfbb0be)
This commit is contained in:
NIIBE Yutaka 2024-06-11 15:21:19 +09:00 committed by Werner Koch
parent a564a9f66c
commit c868d23f61
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -511,13 +511,12 @@ daemon_start (enum daemon_type type, ctrl_t ctrl)
}
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);
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);
if (ctx)
assuan_release (ctx);
@ -526,6 +525,9 @@ daemon_start (enum daemon_type type, ctrl_t ctrl)
{
ctrl->d_local[type]->ctx = ctx;
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;
}