Mercurial > dovecot > core-2.2
changeset 21414:355ebf12f384
dict-file: Fix potential crash when doing other dict calls during iteration.
If file was refreshed, the hash table was cleared, which broke the existing
iterators.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Mon, 16 Jan 2017 16:58:31 +0200 |
parents | 91187182279c |
children | d749ca18af65 |
files | src/lib-dict/dict-file.c |
diffstat | 1 files changed, 9 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-dict/dict-file.c Mon Jan 16 17:12:41 2017 +0200 +++ b/src/lib-dict/dict-file.c Mon Jan 16 16:58:31 2017 +0200 @@ -110,6 +110,12 @@ { struct stat st1, st2; + if (dict->dict.iter_count > 0) { + /* Change nothing while there are iterators or they can crash + because the hash table content recreated. */ + return FALSE; + } + if (dict->fd == -1) return TRUE; @@ -171,7 +177,7 @@ if (file_dict_open_latest(dict) < 0) return -1; - if (dict->refreshed) + if (dict->refreshed || dict->dict.iter_count > 0) return 0; hash_table_clear(dict->hash, TRUE); @@ -229,10 +235,11 @@ ctx->paths[i].len = strlen(paths[i]); } ctx->flags = flags; - ctx->iter = hash_table_iterate_init(dict->hash); if (file_dict_refresh(dict) < 0) ctx->failed = TRUE; + + ctx->iter = hash_table_iterate_init(dict->hash); return &ctx->ctx; }