aboutsummaryrefslogtreecommitdiffstats
path: root/dirmngr/ks-engine-hkp.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2018-09-11 05:04:37 +0000
committerNIIBE Yutaka <[email protected]>2018-09-11 05:04:37 +0000
commit69bab1cba07a8259b85a7911c2824724667803a4 (patch)
treedf4e741e8c8cb4f0ec9235d4b2669cc37db48b01 /dirmngr/ks-engine-hkp.c
parentdirmngr: Serialize access to hosttable. (diff)
downloadgnupg-69bab1cba07a8259b85a7911c2824724667803a4.tar.gz
gnupg-69bab1cba07a8259b85a7911c2824724667803a4.zip
Revert "dirmngr: hkp: Avoid potential race condition when some hosts die."
This reverts commit 04b56eff118ec34432c368b87e724bce1ac683f9. -- Now the access to hosttable is serialized correctly.
Diffstat (limited to 'dirmngr/ks-engine-hkp.c')
-rw-r--r--dirmngr/ks-engine-hkp.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/dirmngr/ks-engine-hkp.c b/dirmngr/ks-engine-hkp.c
index 9c234ec44..31fa77284 100644
--- a/dirmngr/ks-engine-hkp.c
+++ b/dirmngr/ks-engine-hkp.c
@@ -224,26 +224,29 @@ host_in_pool_p (hostinfo_t hi, int tblidx)
static int
select_random_host (hostinfo_t hi)
{
- int *tbl = NULL;
- size_t tblsize = 0;
+ int *tbl;
+ size_t tblsize;
int pidx, idx;
/* We create a new table so that we randomly select only from
currently alive hosts. */
- for (idx = 0;
+ for (idx = 0, tblsize = 0;
idx < hi->pool_len && (pidx = hi->pool[idx]) != -1;
idx++)
if (hosttable[pidx] && !hosttable[pidx]->dead)
- {
- tblsize++;
- tbl = xtryrealloc(tbl, tblsize * sizeof *tbl);
- if (!tbl)
- return -1; /* memory allocation failed! */
- tbl[tblsize-1] = pidx;
- }
+ tblsize++;
if (!tblsize)
return -1; /* No hosts. */
+ tbl = xtrymalloc (tblsize * sizeof *tbl);
+ if (!tbl)
+ return -1;
+ for (idx = 0, tblsize = 0;
+ idx < hi->pool_len && (pidx = hi->pool[idx]) != -1;
+ idx++)
+ if (hosttable[pidx] && !hosttable[pidx]->dead)
+ tbl[tblsize++] = pidx;
+
if (tblsize == 1) /* Save a get_uint_nonce. */
pidx = tbl[0];
else