diff options
author | Werner Koch <[email protected]> | 2019-05-14 17:05:58 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2019-05-16 12:01:57 +0000 |
commit | 6f72aa821407e47ad3963e72e139f2ca2c69d9dd (patch) | |
tree | 2873773aa421000a511d0fe350620656df449424 /kbx/keybox-search.c | |
parent | gpgconf: Before --launch check that the config file is fine. (diff) | |
download | gnupg-6f72aa821407e47ad3963e72e139f2ca2c69d9dd.tar.gz gnupg-6f72aa821407e47ad3963e72e139f2ca2c69d9dd.zip |
kbx: Fix deadlock in gpgsm on Windows due to a sharing violation.
* kbx/keybox-init.c (keybox_lock) [W32]: Use _keybox_close_file
instead of fclose so that a close is done if the file is opened by
another handle.
* kbx/keybox-search.c (keybox_search): Remember the last offset and
use that in NEXT search mode if we had to re-open the file.
--
GnuPG-bug-id: 4505
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to '')
-rw-r--r-- | kbx/keybox-search.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c index 1f5dbdf97..9c396449a 100644 --- a/kbx/keybox-search.c +++ b/kbx/keybox-search.c @@ -844,16 +844,21 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc, KEYBOXBLOB blob = NULL; struct sn_array_s *sn_array = NULL; int pk_no, uid_no; + off_t lastfoundoff; if (!hd) return gpg_error (GPG_ERR_INV_VALUE); - /* clear last found result */ + /* Clear last found result but reord the offset of the last found + * blob which we may need later. */ if (hd->found.blob) { + lastfoundoff = _keybox_get_blob_fileoffset (hd->found.blob); _keybox_release_blob (hd->found.blob); hd->found.blob = NULL; } + else + lastfoundoff = 0; if (hd->error) return hd->error; /* still in error state */ @@ -872,6 +877,7 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc, case KEYDB_SEARCH_MODE_FIRST: /* always restart the search in this mode */ keybox_search_reset (hd); + lastfoundoff = 0; break; default: break; @@ -896,6 +902,32 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc, xfree (sn_array); return rc; } + /* log_debug ("%s: re-opened file\n", __func__); */ + if (ndesc && desc[0].mode == KEYDB_SEARCH_MODE_NEXT && lastfoundoff) + { + /* Search mode is next and the last search operation + * returned a blob which also was not the first one. We now + * need to skip over that blob and hope that the file has + * not changed. */ + if (fseeko (hd->fp, lastfoundoff, SEEK_SET)) + { + rc = gpg_error_from_syserror (); + log_debug ("%s: seeking to last found offset failed: %s\n", + __func__, gpg_strerror (rc)); + xfree (sn_array); + return gpg_error (GPG_ERR_NOTHING_FOUND); + } + /* log_debug ("%s: re-opened file and sought to last offset\n", */ + /* __func__); */ + rc = _keybox_read_blob (NULL, hd->fp, NULL); + if (rc) + { + log_debug ("%s: skipping last found blob failed: %s\n", + __func__, gpg_strerror (rc)); + xfree (sn_array); + return gpg_error (GPG_ERR_NOTHING_FOUND); + } + } } /* Kludge: We need to convert an SN given as hexstring to its binary |