Check user-supplied JID, change memory allocation tracking logic
authorMikael Berthe <mikael@lilotux.net>
Sat, 04 Aug 2012 12:17:57 +0200
changeset 23 66455f258c64
parent 22 cbae62eecb1d
child 24 5254ab4a5f24
Check user-supplied JID, change memory allocation tracking logic
marking.c
--- a/marking.c	Sun Jul 22 15:37:10 2012 +0300
+++ b/marking.c	Sat Aug 04 12:17:57 2012 +0200
@@ -70,18 +70,26 @@
 	if (args[0]) {
 		cmd = args[0];
 
-		if (args[1])
-			jid = jidtodisp (args[1]);
+		if (args[1]) {
+            const char *j = args[1];
+            if (check_jid_syntax(j)) {
+                scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
+                             "<%s> is not a valid Jabber ID.", j);
+                return;
+            }
+			jid = jidtodisp(j);
+            jfree = TRUE;
+        }
 	} else
 		cmd = "set";
-	
+
 	if (!strcmp (cmd, "set")) {
 
 		if (!g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0)) {
 			marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID));
 			marked = 1;
-		} else
-			jfree = TRUE;
+			jfree = FALSE;
+		}
 
 	} else if (!strcmp (cmd, "clear")) {
 
@@ -93,8 +101,6 @@
 			marked = 0;
 		}
 
-		jfree = TRUE;
-
 	} else if (!strcmp (cmd, "toggle")) {
 
 		GSList *mel = g_slist_find_custom (marked_jids, jid ? jid : CURRENT_JID, (GCompareFunc) g_strcmp0);
@@ -103,10 +109,10 @@
 			g_free (mel->data);
 			marked_jids = g_slist_delete_link (marked_jids, mel);
 			marked = 0;
-			jfree  = TRUE;
 		} else {
 			marked_jids = g_slist_append (marked_jids, jid ? jid : g_strdup (CURRENT_JID));
 			marked = 1;
+			jfree  = FALSE;
 		}
 	}