Ethereal-dev: [Ethereal-dev] crash in follow_stream_cb

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Andrew Hood <ajhood@xxxxxxxxx>
Date: Sun, 07 Dec 2003 17:39:10 +1100
Ethereal CVS as of about 24 hrs ago compiled to use gtk2
Slackware 8.1 patched to 2.4.21
gtk+ 2.3.0

If I select a TCP packet and right click "follow stream" all is OK.

If instead I select analyse->follow stream I get a crash in follow_stream_cb

It appears
 	filter_te = OBJECT_GET_DATA(w, E_DFILTER_TE_KEY);
is returning NULL.

This NULL pointer gets used all over the following code (especially to find previous_filter) until
	if(strlen(previous_filter)) {
tries to use to it.

If I test for each of these being NULL and bypass the code (see attached diff) it runs and filters as requested but doesn't fill in the filter box at the bottom of the window.

--
There's no point in being grown up if you can't be childish sometimes.
                -- Dr. Who
--- follow_dlg.c	2003-12-07 15:10:00.000000000 +1100
+++ follow_dlg.c-tmp	2003-12-07 16:56:14.000000000 +1100
@@ -155,7 +155,7 @@
 	GtkWidget	*stream_om, *stream_menu, *stream_mi;
 	int		tmp_fd;
 	gchar		*follow_filter;
-	const gchar	*previous_filter;
+	const gchar	*previous_filter=NULL;
 	const char	*hostname0, *hostname1;
 	char		*port0, *port1;
 	char		string[128];
@@ -214,22 +214,31 @@
 	follow_info->filter_te = filter_te;
 
 	/* save previous filter, const since we're not supposed to alter */
-	previous_filter =
-	    (const gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
+	if (filter_te) {
+	    previous_filter =
+		(const gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
+	}
 
 	/* allocate our new filter. API claims g_malloc terminates program on failure */
 	/* my calc for max alloc needed is really +10 but when did a few extra bytes hurt ? */
-	follow_info->filter_out_filter =
-	    (gchar *)g_malloc(strlen(follow_filter) + strlen(previous_filter) + 16);
+	if (previous_filter) {
+	    follow_info->filter_out_filter =
+		(gchar *)g_malloc(strlen(follow_filter) + strlen(previous_filter) + 16);
+	} else {
+	    follow_info->filter_out_filter =
+		(gchar *)g_malloc(strlen(follow_filter) + 16);
+	}
 
 	/* append the negation */
-	if(strlen(previous_filter)) {
+	if(previous_filter && strlen(previous_filter)) {
 	    sprintf(follow_info->filter_out_filter, "%s \nand !(%s)", previous_filter, follow_filter);
 	} else {
 	    sprintf(follow_info->filter_out_filter, "!(%s)", follow_filter);
 	}
 
-	gtk_entry_set_text(GTK_ENTRY(filter_te), follow_filter);
+	if (filter_te) {
+	    gtk_entry_set_text(GTK_ENTRY(filter_te), follow_filter);
+	}
 
 	/* Run the display filter so it goes in effect. */
 	filter_packets(&cfile, follow_filter);