Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-users: Re: [Ethereal-users] Packet crashes Ethereal

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: Fri, 25 Oct 2002 14:16:10 -0700
On Fri, Oct 25, 2002 at 09:24:50PM +0200, Martin Regner wrote:
> On way to solve this could be to instead use a temporar variable instead
> of overwriting the offset variable
> temp_offset = tvb_find_guint8(tvb,offset,len,TN_IAC) 
> and only copy temp_offset  to the offset variable when temp_offset
> is not equal to -1.

Another way is to assign to "iac_offset" and:

	if it's -1, add "len" to offset;

	otherwise, assign "iac_offset" to "offset".

Also, it turns out it wasn't putting an entry into the protocol tree for
unknown Telnet commands (the data in the capture doesn't look like
regular Telnet data, with IACs and all that other NVT stuff, so it turns
out to have been a good test).

I've attached a patch giving the changes I checked in.
Index: packet-telnet.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-telnet.c,v
retrieving revision 1.32
retrieving revision 1.34
diff -c -r1.32 -r1.34
*** packet-telnet.c	28 Aug 2002 21:00:36 -0000	1.32
--- packet-telnet.c	25 Oct 2002 21:13:38 -0000	1.34
***************
*** 120,125 ****
--- 120,126 ----
    guint8 opt_byte;
    int subneg_len, req;
    const guchar *opt;
+   int iac_offset;
    guint len;
  
    offset += 2;	/* skip IAC and SB */
***************
*** 136,146 ****
  
    /* Search for an IAC. */
    len = tvb_length_remaining(tvb, offset);
!   offset = tvb_find_guint8(tvb, offset, len, TN_IAC);
!   if (offset == -1) {
      /* None found - run to the end of the packet. */
      offset += len;
!   }
  
    subneg_len = offset - start_offset;
  
--- 137,148 ----
  
    /* Search for an IAC. */
    len = tvb_length_remaining(tvb, offset);
!   iac_offset = tvb_find_guint8(tvb, offset, len, TN_IAC);
!   if (iac_offset == -1) {
      /* None found - run to the end of the packet. */
      offset += len;
!   } else
!     offset = iac_offset;
  
    subneg_len = offset - start_offset;
  
***************
*** 285,290 ****
--- 287,297 ----
    case TN_DONT:
      offset = telnet_will_wont_do_dont(telnet_tree, tvb, start_offset,
  					"Don't");
+     break;
+ 
+   default:
+     proto_tree_add_text(telnet_tree, tvb, start_offset, 2,
+ 			"Command: Unknown (0x%02x)", optcode);
      break;
    }