evolution-data-server r9633 - branches/gnome-2-24/libedataserverui



Author: mcrha
Date: Wed Oct  1 07:44:19 2008
New Revision: 9633
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9633&view=rev

Log:
2008-10-01  Milan Crha  <mcrha redhat com>

	** Fix for bug #514670

	* e-passwords.c: (check_key_file), (ep_key_file_load),
	(ep_key_file_save), (ep_clear_passwords_keyfile),
	(ep_forget_passwords_keyfile), (ep_remember_password_keyfile),
	(ep_forget_password_keyfile), (ep_get_password_keyfile):
	Check for errors properly. Also do not use uninitialized variables.



Modified:
   branches/gnome-2-24/libedataserverui/ChangeLog
   branches/gnome-2-24/libedataserverui/e-passwords.c

Modified: branches/gnome-2-24/libedataserverui/e-passwords.c
==============================================================================
--- branches/gnome-2-24/libedataserverui/e-passwords.c	(original)
+++ branches/gnome-2-24/libedataserverui/e-passwords.c	Wed Oct  1 07:44:19 2008
@@ -98,6 +98,15 @@
 #define KEY_FILE_GROUP_PREFIX "Passwords-"
 static GKeyFile *key_file = NULL;
 
+static gboolean
+check_key_file (const char *funcname)
+{
+	if (!key_file)
+		g_message ("%s: Failed to create key file!", funcname);
+
+	return key_file != NULL;
+}
+
 static gchar *
 ep_key_file_get_filename (void)
 {
@@ -140,6 +149,9 @@
 	gchar *filename;
 	GError *error = NULL;
 
+	if (!check_key_file (G_STRFUNC))
+		return;
+
 	filename = ep_key_file_get_filename ();
 
 	if (!g_file_test (filename, G_FILE_TEST_EXISTS))
@@ -163,13 +175,17 @@
 {
 	gchar *contents;
 	gchar *filename;
-	gsize length;
+	gsize length = 0;
 	GError *error = NULL;
 
+	if (!check_key_file (G_STRFUNC))
+		return;
+
 	filename = ep_key_file_get_filename ();
-	contents = g_key_file_to_data (key_file, &length, NULL);
+	contents = g_key_file_to_data (key_file, &length, &error);
 
-	g_file_set_contents (filename, contents, length, &error);
+	if (!error)
+		g_file_set_contents (filename, contents, length, &error);
 
 	if (error != NULL) {
 		g_warning ("%s", error->message);
@@ -542,6 +558,9 @@
 	gchar *group;
 	GError *error = NULL;
 
+	if (!check_key_file (G_STRFUNC))
+		return;
+
 	group = ep_key_file_get_group (msg->component);
 
 	if (g_key_file_remove_group (key_file, group, &error))
@@ -599,9 +618,16 @@
 ep_forget_passwords_keyfile (EPassMsg *msg)
 {
 	gchar **groups;
-	gsize length, ii;
+	gsize length = 0, ii;
+
+	if (!check_key_file (G_STRFUNC))
+		return;
 
 	groups = g_key_file_get_groups (key_file, &length);
+
+	if (!groups)
+		return;
+
 	for (ii = 0; ii < length; ii++) {
 		GError *error = NULL;
 
@@ -690,8 +716,10 @@
 	password = ep_password_encode (password);
 
 	g_hash_table_remove (password_cache, msg->key);
-	g_key_file_set_string (key_file, group, key, password);
-	ep_key_file_save ();
+	if (check_key_file (G_STRFUNC)) {
+		g_key_file_set_string (key_file, group, key, password);
+		ep_key_file_save ();
+	}
 
 	g_free (group);
 	g_free (key);
@@ -753,6 +781,9 @@
 	gchar *group, *key;
 	GError *error = NULL;
 
+	if (!check_key_file (G_STRFUNC))
+		return;
+
 	group = ep_key_file_get_group (msg->component);
 	key = ep_key_file_normalize_key (msg->key);
 
@@ -882,6 +913,9 @@
 	gchar *group, *key, *password;
 	GError *error = NULL;
 
+	if (!check_key_file (G_STRFUNC))
+		return;
+
 	group = ep_key_file_get_group (msg->component);
 	key = ep_key_file_normalize_key (msg->key);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]