Mercurial > dovecot > core-2.2
changeset 21292:25b0616d7f1c
mail-crypt: Ensure array is created before accessing it
Fixes segmentation fault on fs-crypt when keys are not
configured.
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Wed, 14 Dec 2016 10:23:17 +0200 |
parents | f07aa4c27bed |
children | 0b5ede227460 |
files | src/plugins/mail-crypt/mail-crypt-global-key.c src/plugins/mail-crypt/test-mail-global-key.c |
diffstat | 2 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/mail-crypt/mail-crypt-global-key.c Wed Dec 14 12:46:50 2016 +0200 +++ b/src/plugins/mail-crypt/mail-crypt-global-key.c Wed Dec 14 10:23:17 2016 +0200 @@ -161,6 +161,9 @@ { const struct mail_crypt_global_private_key *priv_key; + if (!array_is_created(&global_keys->private_keys)) + return NULL; + array_foreach(&global_keys->private_keys, priv_key) { if (strcmp(priv_key->key_id, pubkey_digest) == 0) return priv_key->key;
--- a/src/plugins/mail-crypt/test-mail-global-key.c Wed Dec 14 12:46:50 2016 +0200 +++ b/src/plugins/mail-crypt/test-mail-global-key.c Wed Dec 14 10:23:17 2016 +0200 @@ -94,6 +94,18 @@ test_end(); } +static void test_empty_keyset(void) +{ + test_begin("test_empty_keyset"); + + /* this should not crash */ + struct mail_crypt_global_keys keys; + memset(&keys, 0, sizeof(keys)); + test_assert(mail_crypt_global_key_find(&keys, "423423423423") == NULL); + + test_end(); +} + static void test_teardown(void) { array_free(&fs_set.plugin_envs); @@ -105,6 +117,7 @@ void (*tests[])(void) = { test_setup, test_try_load_keys, + test_empty_keyset, test_teardown, NULL };