[PATCH 2/5] dirmngr: hkp: avoid race condition when some hosts die

Werner Koch wk at gnupg.org
Tue Nov 1 12:06:06 CET 2016

On Tue,  1 Nov 2016 01:33, dkg at fifthhorseman.net said:

> Multiple threads may write to hosttable[x]->dead while
> select_random_host() is running.  For example, a housekeeping thread

Nope.  Please look at the code:

  for (idx=0, tblsize=0; (pidx = table[idx]) != -1; idx++)
    if (hosttable[pidx] && !hosttable[pidx]->dead)
  if (!tblsize)
    return -1; /* No hosts.  */

  tbl = xtrymalloc (tblsize * sizeof *tbl);
  if (!tbl)
    return -1;
  for (idx=0, tblsize=0; (pidx = table[idx]) != -1; idx++)
    if (hosttable[pidx] && !hosttable[pidx]->dead)
      tbl[tblsize++] = pidx;

  if (tblsize == 1)  /* Save a get_uint_nonce.  */
    pidx = tbl[0];
    pidx = tbl[get_uint_nonce () % tblsize];

and explain where you see a syscall which may switch to another thread.
Neither xtrymalloc nor get_unit_nonce are such syscalls or supposed to
use nPth wrapper syscalls.

I agree that the use of get_unit_nonce is a bit fragile because we can't
immediatly see how it is implemented and thus would be better to get its
value at the start of the function.



Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: </pipermail/attachments/20161101/472d93c2/attachment-0001.sig>

More information about the Gnupg-devel mailing list