Ethereal-users: Re: [Ethereal-users] IPP attribute_fidelity decoding bug in Ethereal version 0.

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, 28 Jan 2003 14:07:09 -0800
On Tue, Jan 28, 2003 at 12:00:25PM -0800, Halsema, Aillil I wrote:
> The ipp_attribute_fidelity attribute's value is an octet. Ethereal is
> decoding it and complaining that the value length should be 4.  This is
> incorrect.  The value length should be 1.

I've checked in a change that should fix that; I've attached a patch in
case you built from source the version of Ethereal you're running.
Index: packet-ipp.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-ipp.c,v
retrieving revision 1.33
diff -c -r1.33 packet-ipp.c
*** packet-ipp.c	28 Aug 2002 21:00:17 -0000	1.33
--- packet-ipp.c	28 Jan 2003 22:01:43 -0000
***************
*** 140,148 ****
  
  static int parse_attributes(tvbuff_t *tvb, int offset, proto_tree *tree);
  static proto_tree *add_integer_tree(proto_tree *tree, tvbuff_t *tvb,
!     int offset, int name_length, int value_length);
  static void add_integer_value(gchar *tag_desc, proto_tree *tree,
!     tvbuff_t *tvb, int offset, int name_length, int value_length);
  static proto_tree *add_octetstring_tree(proto_tree *tree, tvbuff_t *tvb,
      int offset, int name_length, int value_length);
  static void add_octetstring_value(gchar *tag_desc, proto_tree *tree,
--- 140,148 ----
  
  static int parse_attributes(tvbuff_t *tvb, int offset, proto_tree *tree);
  static proto_tree *add_integer_tree(proto_tree *tree, tvbuff_t *tvb,
!     int offset, int name_length, int value_length, guint8 tag);
  static void add_integer_value(gchar *tag_desc, proto_tree *tree,
!     tvbuff_t *tvb, int offset, int name_length, int value_length, guint8 tag);
  static proto_tree *add_octetstring_tree(proto_tree *tree, tvbuff_t *tvb,
      int offset, int name_length, int value_length);
  static void add_octetstring_value(gchar *tag_desc, proto_tree *tree,
***************
*** 384,393 ****
  					 */
  					attr_tree = add_integer_tree(as_tree,
  					    tvb, offset, name_length,
! 					    value_length);
  				}
  				add_integer_value(tag_desc, attr_tree, tvb,
! 				    offset, name_length, value_length);
  				break;
  
  			case TAG_TYPE_OCTETSTRING:
--- 384,393 ----
  					 */
  					attr_tree = add_integer_tree(as_tree,
  					    tvb, offset, name_length,
! 					    value_length, tag);
  				}
  				add_integer_value(tag_desc, attr_tree, tvb,
! 				    offset, name_length, value_length, tag);
  				break;
  
  			case TAG_TYPE_OCTETSTRING:
***************
*** 427,465 ****
  	return offset;
  }
  
  static proto_tree *
  add_integer_tree(proto_tree *tree, tvbuff_t *tvb, int offset,
!     int name_length, int value_length)
  {
  	proto_item *ti;
  
! 	if (value_length != 4) {
! 		ti = proto_tree_add_text(tree, tvb, offset,
! 		    1 + 2 + name_length + 2 + value_length,
! 		    "%.*s: Invalid integer (length is %u, should be 4)",
! 		    name_length,
! 		    tvb_get_ptr(tvb, offset + 1 + 2, name_length),
! 		    value_length);
! 	} else {
  		ti = proto_tree_add_text(tree, tvb, offset,
  		    1 + 2 + name_length + 2 + value_length,
! 		    "%.*s: %u",
  		    name_length,
  		    tvb_get_ptr(tvb, offset + 1 + 2, name_length),
! 		    tvb_get_ntohl(tvb, offset + 1 + 2 + name_length + 2));
  	}
  	return proto_item_add_subtree(ti, ett_ipp_attr);
  }
  
  static void
  add_integer_value(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
!     int offset, int name_length, int value_length)
  {
  	offset = add_value_head(tag_desc, tree, tvb, offset, name_length,
  	    value_length);
! 	if (value_length == 4) {
! 		proto_tree_add_text(tree, tvb, offset, value_length,
! 		    "Value: %u", tvb_get_ntohl(tvb, offset));
  	}
  }
  
--- 427,525 ----
  	return offset;
  }
  
+ static const value_string bool_vals[] = {
+ 	{ 0x00, "false" },
+ 	{ 0x01, "true" },
+ 	{ 0,    NULL }
+ };
+ 
  static proto_tree *
  add_integer_tree(proto_tree *tree, tvbuff_t *tvb, int offset,
!     int name_length, int value_length, guint8 tag)
  {
  	proto_item *ti;
+ 	guint8 bool_val;
  
! 	switch (tag) {
! 
! 	case TAG_BOOLEAN:
! 		if (value_length != 1) {
! 			ti = proto_tree_add_text(tree, tvb, offset,
! 			    1 + 2 + name_length + 2 + value_length,
! 			    "%.*s: Invalid boolean (length is %u, should be 1)",
! 			    name_length,
! 			    tvb_get_ptr(tvb, offset + 1 + 2, name_length),
! 			    value_length);
! 		} else {
! 			bool_val = tvb_get_guint8(tvb,
! 			    offset + 1 + 2 + name_length + 2);
! 			ti = proto_tree_add_text(tree, tvb, offset,
! 			    1 + 2 + name_length + 2 + value_length,
! 			    "%.*s: %s",
! 			    name_length,
! 			    tvb_get_ptr(tvb, offset + 1 + 2, name_length),
! 			    val_to_str(bool_val, bool_vals, "Unknown (0x%02x)"));
! 		}
! 		break;
! 
! 	case TAG_INTEGER:
! 	case TAG_ENUM:
! 		if (value_length != 4) {
! 			ti = proto_tree_add_text(tree, tvb, offset,
! 			    1 + 2 + name_length + 2 + value_length,
! 			    "%.*s: Invalid integer (length is %u, should be 4)",
! 			    name_length,
! 			    tvb_get_ptr(tvb, offset + 1 + 2, name_length),
! 			    value_length);
! 		} else {
! 			ti = proto_tree_add_text(tree, tvb, offset,
! 			    1 + 2 + name_length + 2 + value_length,
! 			    "%.*s: %u",
! 			    name_length,
! 			    tvb_get_ptr(tvb, offset + 1 + 2, name_length),
! 			    tvb_get_ntohl(tvb, offset + 1 + 2 + name_length + 2));
! 		}
! 		break;
! 
! 	default:
  		ti = proto_tree_add_text(tree, tvb, offset,
  		    1 + 2 + name_length + 2 + value_length,
! 		    "%.*s: Unknown integer type 0x%02x",
  		    name_length,
  		    tvb_get_ptr(tvb, offset + 1 + 2, name_length),
! 		    tag);
! 		break;
  	}
  	return proto_item_add_subtree(ti, ett_ipp_attr);
  }
  
  static void
  add_integer_value(gchar *tag_desc, proto_tree *tree, tvbuff_t *tvb,
!     int offset, int name_length, int value_length, guint8 tag)
  {
+ 	guint8 bool_val;
+ 
  	offset = add_value_head(tag_desc, tree, tvb, offset, name_length,
  	    value_length);
! 
! 	switch (tag) {
! 
! 	case TAG_BOOLEAN:
! 		if (value_length == 1) {
! 			bool_val = tvb_get_guint8(tvb, offset);
! 			proto_tree_add_text(tree, tvb, offset, value_length,
! 			    "Value: %s",
! 			    val_to_str(bool_val, bool_vals, "Unknown (0x%02x)"));
! 		}
! 		break;
! 
! 	case TAG_INTEGER:
! 	case TAG_ENUM:
! 		if (value_length == 4) {
! 			proto_tree_add_text(tree, tvb, offset, value_length,
! 			    "Value: %u", tvb_get_ntohl(tvb, offset));
! 		}
! 		break;
  	}
  }