changeset 14821:5e5b34ac509a

[gaim-migrate @ 17588] Don't rely on the sender or receiver of messages being a buddy, and add some other safeguards to prevent crashes like bug #1585017 I'm pretty sure this is good, but don't have the necessary sqlite installed to test this at the moment. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 26 Oct 2006 15:55:31 +0000
parents 77c68f898389
children ac0ce6064000
files gtk/plugins/cap/cap.c
diffstat 1 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/plugins/cap/cap.c	Thu Oct 26 06:20:18 2006 +0000
+++ b/gtk/plugins/cap/cap.c	Thu Oct 26 15:55:31 2006 +0000
@@ -109,6 +109,9 @@
 static CapStatistics * get_stats_for(GaimBuddy *buddy) {
 	gchar *buddy_name;
 	CapStatistics *stats;
+
+	g_return_val_if_fail(buddy != NULL, NULL);
+
 	buddy_name = g_strdup(buddy->name);
 	stats = g_hash_table_lookup(_buddy_stats, buddy_name);
 	if(!stats) {
@@ -340,9 +343,17 @@
 
 /* sent-im-msg */
 static void sent_im_msg(GaimAccount *account, const char *receiver, const char *message) {
-	GaimBuddy *buddy = gaim_find_buddy(account, receiver);
-	guint interval = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60;
-	guint words = word_count(message);
+	GaimBuddy *buddy;
+	guint interval, words;
+
+	buddy = gaim_find_buddy(account, receiver);
+
+	if (buddy == NULL)
+		return;
+
+	interval = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60;
+	words = word_count(message);
+
 	CapStatistics *stats = get_stats_for(buddy);
 
 	insert_word_count(gaim_account_get_username(account), receiver, words);
@@ -357,9 +368,16 @@
 /* received-im-msg */
 static void
 received_im_msg(GaimAccount *account, char *sender, char *message, GaimConversation *conv, GaimMessageFlags flags) {
-	GaimBuddy *buddy = gaim_find_buddy(account, sender);
+	GaimBuddy *buddy;
+	CapStatistics *stats;
 	/* guint words = word_count(message); */
-	CapStatistics *stats = get_stats_for(buddy);
+
+	buddy = gaim_find_buddy(account, sender);
+
+	if (buddy == NULL)
+		return;
+
+	stats = get_stats_for(buddy);
 
 	/* insert_word_count(sender, buddy_name, words); */