Wireshark-dev: Re: [Wireshark-dev] [PATCH][Update] stats_tree.c fixup preventing segfault
From: Sebastien Tandel <sebastien@xxxxxxxxx>
Date: Thu, 14 Dec 2006 01:14:12 +0100

I  don't see exactly what could have been changed between the both
implementations in their doc but I may miss something
http://developer.gnome.org/doc/API/2.0/glib/glib-String-Utility-Functions.html#g-strsplit
http://developer.gnome.org/doc/API/glib/glib-string-utility-functions.html#G-STRSPLIT


Nevertheless the fact is that there is a difference in g_strsplit
between glib 1.2 and 2.0 :

when wanting to split "1-" or "-" with the "-" delimiter  and a
max_tokens of 2,

glib1.2 will return  { "1", NULL } / { "", NULL }
glib2 will return { "1", "" } / { "", "" }

I therefore changed slightly the patch to take this into account.



Regards,
Sebastien Tandel




Sebastien Tandel wrote:
> Hi Stephen,
>
> it's just after ... I leave the filter empty and click create stats :)
>
> see in the code plugins/pinfo_stats_tree.c line 97 :
>         st_node_plen = stats_tree_create_range_node(st, st_str_plen, 0,
> "0-19","20-39","40-79","80-159","160-319","320-639","640-1279","1280-2559","2560-5119","5120-",NULL);
>
>
> Anyway, when you asked me how to reproduce it did not crash anymore
> (ouchh...). Strange.
> However, I remember that I got rid of glib/gtk1.2 yesterday to finally
> arrive to something which seems really better, in terms of graphical
> interface, gtk+2 (even if I'm merely a command line lover :))  And it
> appears that this "slight" change made wireshark more robust or maybe I
> was just concerned by an hallucination? :-/
>
> I therefore installed again (just for you :)) glib/gtk1.2 and start a
> new compile process (tooooo long) to see what happens ... and here is
> one config on which it crashes :
> --------------------------
> wireshark 0.99.5 (SVN Rev 20130)
>
> Copyright 1998-2006 Gerald Combs <gerald@xxxxxxxxxxxxx> and contributors.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> Compiled with GTK+ 1.2.10, with GLib 1.2.10, with libpcap 0.7.2, with libz
> 1.2.3, with libpcre 5.0, without UCD-SNMP or Net-SNMP, with ADNS,
> without Lua,
> with GnuTLS 1.4.4, with Gcrypt 1.2.3, without Kerberos, without PortAudio,
> without AirPcap.
>
> Running on Linux 2.6.17.7, with libpcap (version unknown).
>
> Built using gcc 4.0.4 20060630 (prerelease) (Debian 4.0.3-5).
> ---------------------------
>
> I did not test the patch on the glib/gtk+2 ... not yet :)
>
>
> Regards,
>
> Sebastien Tandel
>
> Stephen Fisher wrote:
>   
>> On Tue, Dec 12, 2006 at 04:41:19AM +0100, Sebastien Tandel wrote:
>>
>>   
>>     
>>>    here is a patch against svn rev20122 which prevents wireshark from 
>>> segfault when trying the stats module "packet length". the function 
>>> affected is get_range in epan/stats_tree.c which did not the correct 
>>> tests if you want define range like the following :
>>>
>>> "-" 
>>> "10-"
>>> "-10"
>>> "0-10"
>>> giving G_MININT (G_MAXINT) if the number is not defined to the left (right).
>>>     
>>>       
>> Where do you go to reproduce this problem?  Statistics->Packet Length 
>> accepts a filter instead of a packet range.
>>   
>>
>> Steve
>> _______________________________________________
>> Wireshark-dev mailing list
>> Wireshark-dev@xxxxxxxxxxxxx
>> http://www.wireshark.org/mailman/listinfo/wireshark-dev
>>   
>>     
>
> _______________________________________________
> Wireshark-dev mailing list
> Wireshark-dev@xxxxxxxxxxxxx
> http://www.wireshark.org/mailman/listinfo/wireshark-dev
>   

Index: epan/stats_tree.c
===================================================================
--- epan/stats_tree.c	(révision 20131)
+++ epan/stats_tree.c	(copie de travail)
@@ -530,12 +530,20 @@
 	
 	split =  g_strsplit(rngstr,"-",2);
 
-	rng->floor = strtol(split[0],NULL,10);
-	rng->ceil  = strtol(split[1],NULL,10);
+	if (*(split[0]) != '\0')
+	  rng->floor = strtol(split[0],NULL,10);
+	else
+	  rng->floor = G_MININT;
+
+#if GLIB_MAJOR_VERSION >= 2
+	if (*(split[1]) != '\0')
+#else
+	if (split[1] != NULL)
+#endif
+	  rng->ceil  = strtol(split[1],NULL,10);
+	else
+	  rng->ceil = G_MAXINT;
 	
-	if (rng->ceil == 0) rng->ceil = G_MAXINT;
-	if (rng->floor == 0) rng->floor = G_MININT;
-
 	g_strfreev(split);
 	
 	return rng;