dovecot-1.1: Handle dict_init() and dict_lookup() failures witho...

dovecot at dovecot.org dovecot at dovecot.org
Sun May 4 18:20:00 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/955ae7b7ad1a
changeset: 7482:955ae7b7ad1a
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 04 18:19:57 2008 +0300
description:
Handle dict_init() and dict_lookup() failures without crashing.

diffstat:

2 files changed, 7 insertions(+), 1 deletion(-)
src/plugins/expire/expire-plugin.c |    5 ++++-
src/plugins/expire/expire-tool.c   |    3 +++

diffs (35 lines):

diff -r 768231eb84cf -r 955ae7b7ad1a src/plugins/expire/expire-plugin.c
--- a/src/plugins/expire/expire-plugin.c	Sun May 04 18:12:28 2008 +0300
+++ b/src/plugins/expire/expire-plugin.c	Sun May 04 18:19:57 2008 +0300
@@ -129,7 +129,8 @@ expire_mailbox_transaction_commit(struct
 			   this is the first mail in the database */
 			ret = dict_lookup(expire.db, pool_datastack_create(),
 					  key, &value);
-			update_dict = ret == 0 || strtoul(value, NULL, 10) == 0;
+			update_dict = ret == 0 ||
+				(ret > 0 && strtoul(value, NULL, 10) == 0);
 			/* may not be exactly the first message's save time
 			   but a few second difference doesn't matter */
 			new_stamp = ioloop_time;
@@ -295,6 +296,8 @@ void expire_plugin_init(void)
 
 		expire.env = expire_env_init(expunge_env, altmove_env);
 		expire.db = dict_init(dict_uri, DICT_DATA_TYPE_UINT32, NULL);
+		if (expire.db == NULL)
+			i_fatal("expire plugin: dict_init() failed");
 		expire.username = getenv("USER");
 
 		expire.next_hook_mail_storage_created =
diff -r 768231eb84cf -r 955ae7b7ad1a src/plugins/expire/expire-tool.c
--- a/src/plugins/expire/expire-tool.c	Sun May 04 18:12:28 2008 +0300
+++ b/src/plugins/expire/expire-tool.c	Sun May 04 18:19:57 2008 +0300
@@ -203,6 +203,9 @@ static void expire_run(bool testrun)
 	ctx.namespace_pool = pool_alloconly_create("namespaces", 1024);
 	env = expire_env_init(getenv("EXPIRE"), getenv("EXPIRE_ALTMOVE"));
 	dict = dict_init(getenv("EXPIRE_DICT"), DICT_DATA_TYPE_UINT32, "");
+	if (dict == NULL)
+		i_fatal("dict_init() failed");
+
 	trans = dict_transaction_begin(dict);
 	iter = dict_iterate_init(dict, DICT_PATH_SHARED,
 				 DICT_ITERATE_FLAG_SORT_BY_VALUE);


More information about the dovecot-cvs mailing list