Ethereal-dev: [Ethereal-dev] tvb_strnlen problem

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

From: Heikki Vatiainen <hessu@xxxxxxxxx>
Date: Fri, 13 Oct 2000 23:47:50 +0300
I am trying to use tvb_strnlen() from a dissector, but keep getting
wrong lengths for valid strings. If I apply a patch like the one
below against tvb_strnlen() function, tvb_strnlen() starts
returning correct values but tvb_get_ntringz() breaks instead.

The code in dissector looks like this:

if (tvb_strnlen(tvb, offset, len) == -1)
  proto_tree_add_text(tree, tvb, offset, len, "<PEP Id not NUL terminated ASCII string>");
else
  proto_tree_add_item(tree, hf_cops_pepid, tvb, offset, tvb_strnlen(tvb, offset, len) + 1,
                      FALSE);


This is the broken patch I came up with:

Index: tvbuff.c
===================================================================
RCS file: /cvsroot/ethereal/epan/tvbuff.c,v
retrieving revision 1.1
diff -u -r1.1 tvbuff.c
--- tvbuff.c	2000/09/27 04:54:53	1.1
+++ tvbuff.c	2000/10/13 20:35:39
@@ -1029,7 +1029,7 @@
 		return -1;
 	}
 	else {
-		return result_offset;
+		return result_offset - abs_offset;
 	}
 }
 

-- 
Heikki Vatiainen                  * hessu@xxxxxxxxx
Tampere University of Technology  * Tampere, Finland