Wireshark-dev: Re: [Wireshark-dev] how to handle dissecting length encoded strings
From: Chris Maynard <chris.maynard@xxxxxxxxx>
Date: Mon, 14 Mar 2011 16:17:17 +0000 (UTC)
Chris Maynard <chris.maynard@...> writes:

Oops, I guess you still need to NULL-terminate context if n_oct is 0:

Index: epan/dissectors/packet-agentx.c
===================================================================
--- epan/dissectors/packet-agentx.c     (revision 36188)
+++ epan/dissectors/packet-agentx.c     (working copy)
@@ -308,8 +308,9 @@
        if (n_oct >= 1024)
                THROW(ReportedBoundsError);
        if (n_oct > 0)
-               tvb_get_nstringz(tvb, offset + 4, n_oct, context);
-       context[n_oct]='\0';
+               tvb_get_nstringz0(tvb, offset + 4, n_oct, context);
+       else
+               context[0]='\0';

        proto_tree_add_uint(tree, hf_ostring_len, tvb, offset, 4, n_oct);
        proto_tree_add_string(tree, hf_ostring, tvb, offset + 4, n_oct, context)
;