Ethereal-dev: Re: [ethereal-dev] packet-netbios bug

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

From: Guy Harris <guy@xxxxxxxxxx>
Date: Tue, 24 Aug 1999 14:46:52 -0700 (PDT)
> I get a segfault when trying to decode this file. I get this stack
> trace, but I'm having a very strange debug session. When I go to stack
> frame 4, I try to print the values for tree and label and I get 0x0 for both.
> But both have non-zero values... look at the function call in the trace below.

I get a segfault on Solaris/SPARC, too.

It appears in frame 4 (which is frame 5 in my stack trace, as the
"snprintf()" being called is the one that comes with Ethereal in my
stack trace, and it blows up one subroutine call later) that "name_type"
is 35 - but the elements of the "name_type_str[]" array have indices 0
through 35, so it's fetching an entry past the end of the array.

The code is checking "name_type", but the check is

	if ( nb_name_type_max < name_type)	/* limit type value */
		name_type = nb_name_type_max;

but, as "nb_name_type_max" is the number of elements in the array, it's
not the maximum value for "name_type", it's one *more* than the maximum
value - indices go from 0 to "nb_name_type_max - 1" - so either
"nb_name_type_max" should be set to

	(sizeof(name_type_str) /sizeof( char*)) - 1

(or to

	(sizeof name_type_str/sizeof name_type_str[0]) - 1

), or the variable should be renamed "num_name_types" or something such
as that and the check be made

	if (name_type >= num_name_types)
		name_type = num_name_types - 1;