changeset 7482:955ae7b7ad1a HEAD

Handle dict_init() and dict_lookup() failures without crashing.
author Timo Sirainen <tss@iki.fi>
date Sun, 04 May 2008 18:19:57 +0300
parents 768231eb84cf
children 591145eaaf87
files src/plugins/expire/expire-plugin.c src/plugins/expire/expire-tool.c
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 			   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 @@
 
 		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 =
--- 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 @@
 	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);