Guy Harris <guy@xxxxxxxxxx> wrote:
> Yes, the problem is that "tvb_strnlen()" is returning the offset of the
> '\0', not the length of the string.
>
> The next problem is that "tvb_get_nstringz()" is assuming that it's
> returning the offset, rather than the length, so "tvb_get_nstringz()"
> should probably do
>
> stringlen = tvb_strnlen(tvb, abs_offset, limit);
>
> /* If NUL wasn't found, copy the data and return -1 */
> if (stringlen == -1) {
> tvb_memcpy(tvb, buffer, abs_offset, limit);
> return -1;
> }
>
> /* Copy the string to buffer */
> tvb_memcpy(tvb, buffer, abs_offset, stringlen + 1);
> return stringlen;
>
> So try changing "tvb_get_nstringz()" as per the above, and see if that
> works.
Thanks, it works now. The whole thing in patch format is below. The
first half of the patch changes tvb_strnlen() to return length, not
offset, and the second half does what was suggested above.
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/16 10:52:08
@@ -1029,7 +1029,7 @@
return -1;
}
else {
- return result_offset;
+ return result_offset - abs_offset;
}
}
@@ -1090,7 +1090,7 @@
gint
tvb_get_nstringz(tvbuff_t *tvb, gint offset, guint maxlength, guint8* buffer)
{
- gint stringlen, NUL_offset;
+ gint stringlen;
guint abs_offset, junk_length;
gint limit;
@@ -1109,16 +1109,15 @@
limit = maxlength;
}
- NUL_offset = tvb_strnlen(tvb, abs_offset, limit);
+ stringlen = tvb_strnlen(tvb, abs_offset, limit);
/* If NUL wasn't found, copy the data and return -1 */
- if (NUL_offset == -1) {
+ if (stringlen == -1) {
tvb_memcpy(tvb, buffer, abs_offset, limit);
return -1;
}
/* Copy the string to buffer */
- stringlen = NUL_offset - abs_offset;
tvb_memcpy(tvb, buffer, abs_offset, stringlen + 1);
return stringlen;
}